﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

using KorbeRTR.Models;
using KorbeRTR.Utility;

namespace KorbeRTR
{
    public partial class FormMainWindow : DevExpress.XtraEditors.XtraForm
    {
        public const int N_前处理段 = 9;
        public const int N_后处理段 = 4;

        public static readonly OmronData OmronPLC;
        public static bool startLogin = false;

        private static bool reFresh料号 = true;

        private DateTime T铜槽数据刷新;
        private DateTime T产线状态刷新;
        private DateTime T水洗压力刷新;

        private Models.CutPicture CutPicture;


        private string BackImage = @"images/8.png";

        static FormMainWindow()
        {
            var ip = "192.168.1.1";
            var port = 9600;
            try
            {
                ip = ConfigurationManager.AppSettings["PLC-IP"];
                port = Convert.ToUInt16(ConfigurationManager.AppSettings["PLC-PORT"]);
            }
            finally
            {
                Console.WriteLine("PLC: " + ip + ":" + port.ToString());
                //ip = "192.168.1.1";
                //port = 9600;
                OmronPLC = new OmronData(ip, port);
            }
        }

        public FormMainWindow()
        {
            InitializeComponent();
            
            

            if (!HslControls.Authorization.SetAuthorizationCode("b90f4629-1cb5-4e7b-b755-64f268c8f807"))
            {
                MessageBox.Show("HslControls 激活失败");
            }
            if (!HslCommunication.Authorization.SetAuthorizationCode("f562cc4c-4772-4b32-bdcd-f3e122c534e3"))
            {
                MessageBox.Show("Communication 激活失败");
            }
        }

        //检测窗体是否打开
        private bool CheckForm(string formName)
        {
            bool bl = false;
            foreach (Form f in Application.OpenForms)
            {
                if (f.Name == formName)
                {
                    bl = true;
                    f.Activate();
                    break;
                }
            }
            return bl;
        }


        /// <summary>
        /// 注销
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmLogout_Click(object sender, EventArgs e)
        {             
            //添加记录
            var record = new OperationRecord()
            {
                Time = DateTime.Now,
                User = Global.GetInstance().CurrentUser.UserName,
                Operation = "注销",
                OperationType = "登入/注销/退出系统"
            };
            OperationRecord.Add(record);

            Global.GetInstance().CurrentUser = null;
            Global.LoginFlag = false;
            startLogin = false;
        }

      

        //温度器温度设定
        private void tsmTemperatureSet_Click(object sender, EventArgs e)
        {
            try
            {
                if (Global.GetInstance().CurrentUser.Check温控器温度设定权限())
                {
                    bool bl = CheckForm(typeof(FormTemperatureSet).Name);
                    if (!bl)
                    {
                        FormTemperatureSet formTemperatureSet = new FormTemperatureSet();
                        formTemperatureSet.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }

        }

        //自动添加设定
        private void tsmAutoAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (Global.GetInstance().CurrentUser.Check自动添加设定权限())
                {
                    bool bl = CheckForm(typeof(Form自动添加设定).Name);
                    if (!bl)
                    {
                        Form自动添加设定 form = new Form自动添加设定();
                        form.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
                    
        }


        //设备参数设定
        private void tsmParamterSet_Click(object sender, EventArgs e)
        {
            try
            {
                if (Global.GetInstance().CurrentUser.Check系统数据权限())
                {
                    bool bl = CheckForm(typeof(FormDeviceParameters).Name);
                    if (!bl)
                    {
                        FormDeviceParameters formDeviceParameters = new FormDeviceParameters();
                        formDeviceParameters.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
      

        }

        //泵浦自动开/关设定
        private void tsmTurnSet_Click(object sender, EventArgs e)
        {
            try
            {
                if (Global.GetInstance().CurrentUser.Check泵浦自动开关设定权限())
                {
                    bool bl = CheckForm(typeof(FormAutoTurnSet).Name);
                    if (!bl)
                    {
                        FormAutoTurnSet formAutoTurnSet = new FormAutoTurnSet();
                        formAutoTurnSet.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
       
            

        }

        //用户权限设定
        private void tsmUserSet_Click(object sender, EventArgs e)
        {
            try
            {
                if (Global.GetInstance().CurrentUser.Check用户权限设定权限())
                {
                    bool bl = CheckForm(typeof(FormUserPurview).Name);
                    if (!bl)
                    {
                        FormUserPurview formUserPurview = new FormUserPurview();
                        formUserPurview.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }

            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
    
        }

        //故障代码设定
        private void tsmErrorCodeSet_Click(object sender, EventArgs e)
        {
            try
            {
                if (Global.GetInstance().CurrentUser.Check故障代码设定权限())
                {
                    bool bl = CheckForm(typeof(FormErrorList).Name);
                    if (!bl)
                    {
                        FormErrorList formErrorList = new FormErrorList();
                        formErrorList.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
         

        }

        /// <summary>
        /// 浮板高度设定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmSetfbHeight_Click(object sender, EventArgs e)
        {
            try
            {
                if (Global.GetInstance().CurrentUser.Check浮板位置设定权限())
                {
                    bool bl = CheckForm(typeof(FormFloatBoardPositionSet).Name);
                    if (!bl)
                    {
                        FormFloatBoardPositionSet form = new FormFloatBoardPositionSet();
                        form.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
        }

        private void tsmS设备洗配槽_Click(object sender, EventArgs e)
        {
            try
            {
                if (Global.GetInstance().CurrentUser.Check洗配槽参数设定权限())
                {
                    //bool bl = CheckForm(typeof(Form设备洗配槽).Name);
                    //if (!bl)
                    //{
                    //    Form设备洗配槽 form = new Form设备洗配槽();
                    //    form.ShowDialog();
                    //}
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
        }

        /// <summary>
        /// 上料记录
        /// </summary>
        private void tsmLoadingRecord_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormProductionRecord).Name);
                if (!bl)
                {
                    FormProductionRecord form = new FormProductionRecord();
                    form.ShowDialog();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
        }

        /// <summary>
        /// 故障记录
        /// </summary>
        private void tsmErrorRecord_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormErrorRecord).Name);
                if (!bl)
                {
                    FormErrorRecord formErrorRecord = new FormErrorRecord();
                    formErrorRecord.ShowDialog();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
          
        }

       

        //操作记录
        private void tsmWorkRecord_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormOperateRecord).Name);
                if (!bl)
                {
                    FormOperateRecord formOperateRecord = new FormOperateRecord();
                    formOperateRecord.ShowDialog();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
          
        }
      

        //温度记录
        private void tsmTemperatureRecord_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormTemperatureRecord).Name);
                if (!bl)
                {
                    FormTemperatureRecord formTemperatureRecord = new FormTemperatureRecord();
                    formTemperatureRecord.ShowDialog();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
        
        }
        

        //电流记录
        private void tsmCurrentRecord_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormCurrentRecord).Name);
                if (!bl)
                {
                    FormCurrentRecord formCurrentRecord = new FormCurrentRecord();
                    formCurrentRecord.ShowDialog();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
       
        }

      

        //系统帮助
        private void tsmHelp_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormHelp).Name);
                if (!bl)
                {
                    FormHelp formHelp = new FormHelp();
                    formHelp.ShowDialog();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
         
        }
        

        //打开生产基础数据
        private void tsmBaseData_Click(object sender, EventArgs e)
        {
            try
            {
                var gl = Global.GetInstance();
                if (gl.CurrentUser.Check产品基本数据操作权限()
                    || gl.CurrentUser.Check生产料号操作权限())
                {
                    bool bl = CheckForm(typeof(FormProductInfo).Name);
                    if (!bl)
                    {
                        FormProductInfo formProductInfo = new FormProductInfo();
                        formProductInfo.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("您无此权限", "错误提示！");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
                  
        }

     
       

        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        //退出
        private void tsBtnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        //退出
        private void FormMainWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (Global.GetInstance().CurrentUser.Check软件退出权限())
            {
                DialogResult result = MessageBox.Show("您是否要退出系统？", "退出提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    //添加记录
                    var record = new OperationRecord()
                    {
                        Time = DateTime.Now,
                        User = Global.GetInstance().CurrentUser.UserName,
                        Operation = "退出系统",
                        OperationType = "登入/注销/退出系统"
                    };
                    OperationRecord.Add(record);

                    OmronPLC.SyncStop();
                    Application.ExitThread();
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("您无此权限", "错误提示！");
                e.Cancel = true;
            }
            
        }
       
        /// <summary>
        /// 打开计算器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmCalculator_Click(object sender, EventArgs e)
        {
            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
            System.Diagnostics.Process proc = new System.Diagnostics.Process();

            //设置外部程序名(记事本用 notepad.exe 计算器用 calc.exe)
            info.FileName = "calc.exe";

            //设置外部程序的启动参数

            info.Arguments = "";

            //设置外部程序工作目录为c:\windows

            info.WorkingDirectory = "c:/windows/";

            try
            {
                //
                //启动外部程序
                //
                proc = System.Diagnostics.Process.Start(info);
            }
            catch
            {
                MessageBox.Show("系统找不到指定的程序文件", "错误提示！");
                return;
            }
        }



        /// <summary>
        /// 打开记事本
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmTxt_Click(object sender, EventArgs e)
        {
            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
            System.Diagnostics.Process proc = new System.Diagnostics.Process();

            //设置外部程序名(记事本用 notepad.exe 计算器用 calc.exe)
            info.FileName = "notepad.exe";

            //设置外部程序的启动参数

            info.Arguments = "";

            //设置外部程序工作目录为c:\windows

            info.WorkingDirectory = "c:/windows/";

            try
            {
                //
                //启动外部程序
                //
                proc = System.Diagnostics.Process.Start(info);
            }
            catch
            {
                MessageBox.Show("系统找不到指定的程序文件", "错误提示！");
                return;
            }
        }


        /// <summary>
        /// 更改密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmChangePassword_Click(object sender, EventArgs e)
        {
            if (Global.GetInstance().CurrentUser.Check更改密码权限())
            {

            }
        }
      


        //重新开始写部分

        //菜单栏实现区

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmLogin_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormLogin).Name);
                if (!bl)
                {
                    FormLogin formLogin = new FormLogin();
                   
                    formLogin.ShowDialog();
                    if (formLogin.logInOk)
                    {
                        //添加记录
                        var record = new OperationRecord()
                        {
                            Time = DateTime.Now,
                            User = Global.GetInstance().CurrentUser.UserName,
                            Operation = "登录系统",
                            OperationType = "登入/注销/退出系统"
                        };
                        OperationRecord.Add(record);

                        tsslblUserInfo.Text = "操作员:" + Global.GetInstance().CurrentUser.UserName.ToString();
                        SetBtnEnable();
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }

        }

        /// <summary>
        /// 登录后设置按键使能
        /// </summary>
        private void SetBtnEnable()
        {
            if (true)
            {
                tsmBaseData.Enabled = true;
                tsmTemperatureSet.Enabled = true;
                tsmAutoAdd.Enabled = true;
                tsmParamterSet.Enabled = true;
                tsmTurnSet.Enabled = true;
                tsmUserSet.Enabled = true;
                tsmErrorCodeSet.Enabled = true;
                tsmS设备洗配槽.Enabled = true;
                tsmSetfbHeight.Enabled = true;
                MuiData.Enabled = true;
                MuiTool.Enabled = true;      
            }
        }

        /// <summary>
        /// 没登录时设置按钮不可用
        /// </summary>
        private void SetBtnDisEnable()
        {        
            tsmBaseData.Enabled = false;
            tsmTemperatureSet.Enabled = false;
            tsmAutoAdd.Enabled = false;
            tsmParamterSet.Enabled = false;
            tsmTurnSet.Enabled = false;
            tsmUserSet.Enabled = false;
            tsmErrorCodeSet.Enabled = false;
            tsmS设备洗配槽.Enabled = false;
            tsmSetfbHeight.Enabled = false;

            MuiData.Enabled = false;
            MuiTool.Enabled = false;
        
        }

        private class 产线AlmMapVauleType
        {
            public string context;
            public int index;
            public Rectangle rectangle;
            public string layer;

            public 产线AlmMapVauleType(int index_, Rectangle rectangle_, string layer_="red")
            {
                index = index_;
                rectangle = rectangle_;
                layer = layer_;
            }
        }
        private Dictionary<string, 产线AlmMapVauleType> 产线AlmMap;
        private Dictionary<string, int> 产线AlmLayer = new Dictionary<string, int>()
        {
            { "blue", 0 },
            { "red", 1 },
            { "yellow", 2}
        };

        private class 产线TextType
        {
            public Utility.HslWapper.Variable<UInt16> lh;
            public Rectangle rectangle;
        }
        private List<产线TextType> 产线TextList;

        private Dictionary<Int64, string> LHNameMap;

        private void Init产线示意图()
        {
            CutPicture = new CutPicture();

            CutPicture.PictureLayers.Add(new Bitmap("images/1.png"));
            CutPicture.PictureLayers.Add(new Bitmap("images/2.png"));
            CutPicture.PictureLayers.Add(new Bitmap("images/3.png"));


            while (OmronPLC.AlarmCodes == null)
            {
                Thread.Sleep(10);
            }

            while (OmronPLC.AlarmCodes.Count == 0)
            {
                Thread.Sleep(10);
            }

            if (产线AlmMap == null)
            {
                产线AlmMap = new Dictionary<string, 产线AlmMapVauleType>()
                {
                    #region 卷入
                    { "卷入长度大于设定长度警报", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                    { "卷入紧急停止", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 100, 25), "red") },
                    { "卷入配重上极限故障", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                    { "卷入纠偏仪极限故障", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                    { "卷入上转轴马达过载", new 产线AlmMapVauleType(-1, new Rectangle(34, 346,50, 58), "red") },
                    { "卷入下转轴马达过载", new 产线AlmMapVauleType(-1, new Rectangle(34, 556, 50, 58), "red") },
                    { "卷入上撕膜马达过载", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                    { "卷入下撕膜马达过载", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                    { "卷入配重下定位超时", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                   
                    #endregion

                    #region 水洗1#        
                    { "1#隔离水洗泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(215, 640, 100, 156), "red") },
                    { "1#隔离水洗下低液位", new 产线AlmMapVauleType(-1, new Rectangle(325, 468, 19, 86), "red") },
                    { "1#隔离水洗L液位预警", new 产线AlmMapVauleType(-1, new Rectangle(343, 468, 360-343, 530-468), "red") },                 
                    { "1#隔离水洗补水电磁阀超时", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 100, 25), "red") },
                    #endregion

                    #region 2#除油
                    { "2#酸性清洁循环泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(415, 640, 100, 156), "red") },
                    { "2#酸性清洁喷流泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(515, 640, 100, 156), "red") },
                    { "2#酸性清洁下槽低液位", new 产线AlmMapVauleType(-1, new Rectangle(547, 468, 19, 86), "red") },
                    { "2#酸性清洁槽L液位预警", new 产线AlmMapVauleType(-1, new Rectangle(564, 470, 16, 60), "red") },
                    { "2#酸性清洁槽(上)槽低液位", new 产线AlmMapVauleType(-1, new Rectangle(568, 162, 22, 23), "red") },
                    { "2#酸性清洁低温报警", new 产线AlmMapVauleType(-1, new Rectangle(461, 449, 62, 24), "red") },
                    { "2#酸性清洁高温报警", new 产线AlmMapVauleType(-1, new Rectangle(461, 449, 62, 24), "red") },                  
                    { "2#酸性清洁槽上盖1保护", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                    { "除油添加泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },

                    #endregion

                    #region 3#热水洗
                    { "3#热水洗循环泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(646, 640, 100, 156), "red") },
                    { "3#热水洗高温报警控", new 产线AlmMapVauleType(-1, new Rectangle(702, 448, 62, 24), "red") },
                    { "3#热水洗高低报警控", new 产线AlmMapVauleType(-1, new Rectangle(702, 448, 62, 24), "red") },
                    { "3#热水洗槽L液位预警", new 产线AlmMapVauleType(-1, new Rectangle(792, 470, 16, 60), "red") },
                    { "3#热水洗下槽低液位", new 产线AlmMapVauleType(-1, new Rectangle(776, 468, 19, 86), "red") },
                    { "3#热水洗(上)槽低液位", new 产线AlmMapVauleType(-1, new Rectangle(793, 164, 22, 31), "red") },
                    { "3#热水洗补水电磁阀超时", new 产线AlmMapVauleType(-1, new Rectangle(699, 529, 35, 41), "red") },
               
                   
                    #endregion

                    #region 4# 水洗
                    { "4#水洗1泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(866, 640, 100, 156), "red") },
                    { "4#水洗1下低液位", new 产线AlmMapVauleType(-1, new Rectangle(982, 468, 19, 86), "red") },
                    { "4#水洗1L液位预警", new 产线AlmMapVauleType(-1, new Rectangle(963, 470, 16, 60), "red") },
                    
               
                   
                    #endregion

                    #region 5# 水洗
                    { "5#水洗2泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(1054, 640, 100, 156), "red") },
                    { "5#水洗2下低液位", new 产线AlmMapVauleType(-1, new Rectangle(1167, 468, 19, 86), "red") },
                    { "5#水洗2L液位预警", new 产线AlmMapVauleType(-1, new Rectangle(1150, 470, 16, 60), "red") },
                    { "5#水洗2补水电磁阀超时", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
 
                    #endregion

                     #region 6#微蚀
                    { "6#微蚀循环泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(1246, 640, 100, 156), "red") },
                    { "6#微蚀喷流泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(1336, 640, 100, 156), "red") },
                    { "6#微蚀下低液位", new 产线AlmMapVauleType(-1, new Rectangle(1371, 468, 19, 86), "red") },
                    { "6#微蚀(上)槽低液位", new 产线AlmMapVauleType(-1, new Rectangle(1392, 164, 22, 23), "red") },
                    { "6#微蚀L液位预警", new 产线AlmMapVauleType(-1, new Rectangle(1390, 470, 16, 60), "red") },
                    { "6#微蚀槽上盖保护", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                    { "微蚀槽高温报警", new 产线AlmMapVauleType(-1, new Rectangle(1289, 448, 62, 24), "red") },
                    { "微蚀槽低温报警", new 产线AlmMapVauleType(-1, new Rectangle(1289, 448, 62, 24), "red") },
                    { "微蚀添加泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
                   

                    #endregion

                    #region 7# 水洗
                    { "7#水洗3泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(1462, 640, 100, 156), "red") },
                    { "7#水洗3下低液位", new 产线AlmMapVauleType(-1, new Rectangle(1561, 468, 19, 86), "red") },
                    { "7#水洗3L液位预警", new 产线AlmMapVauleType(-1, new Rectangle(1578, 470, 16, 60), "red") },
          
                    #endregion

                    #region 8# 水洗
                    { "8#水洗4泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(1644, 640, 100, 156), "red") },
                    { "8#水洗4下低液位", new 产线AlmMapVauleType(-1, new Rectangle(1749, 468, 19, 86), "red") },
                    { "8#水洗4L液位预警", new 产线AlmMapVauleType(-1, new Rectangle(1767, 470, 16, 60), "red") },
                    { "8#水洗4补水电磁阀超时", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
 
                    #endregion

                    #region 9#酸浸
                    { "9#酸浸循环泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(1841, 640, 100, 156), "red") },
                    { "9#酸浸喷流泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(1938, 640, 100, 156), "red") },
                    { "9#酸浸下低液位", new 产线AlmMapVauleType(-1, new Rectangle(1970, 468, 19, 86), "red") },
                    { "9#酸浸（上）槽低液位", new 产线AlmMapVauleType(-1, new Rectangle(1991, 168, 22, 23), "red") },
                    { "9#酸浸槽上盖保护", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },

                    #endregion

                    #region 1#导电段
                    { "1#导电段泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(2128, 640, 100, 156), "red") },
                    { "1#导电段下低液位", new 产线AlmMapVauleType(-1, new Rectangle(2195, 534, 22, 23), "red") },
                    { "1#导电段下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(2212, 510, 22, 23), "red") },
                    { "1#导电段1电流异常", new 产线AlmMapVauleType(-1, new Rectangle(2095, 260, 25, 38), "red") },
                    { "1#导电段2电流异常", new 产线AlmMapVauleType(-1, new Rectangle(2120, 260, 25, 38), "red") },
                    { "1#导电段3电流异常", new 产线AlmMapVauleType(-1, new Rectangle(2145, 260, 25, 38), "red") },
                    { "1#导电段4电流异常", new 产线AlmMapVauleType(-1, new Rectangle(2170, 260, 25, 38), "red") },
                    { "1#导电段5电流异常", new 产线AlmMapVauleType(-1, new Rectangle(2195, 260, 25, 38), "red") },

                    #endregion

                          #region 铜槽1
                    { "1#铜槽上喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(2295, 640, 100, 156), "red") },
                    { "铜槽循环泵1#过载", new 产线AlmMapVauleType(-1, new Rectangle(2430, 640, 100, 156), "red") },
                    { "1#铜槽下喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(2543, 640, 100, 156), "red") },
                    { "1#铜槽上低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(2300, 1, 44, 44), "red") },
                    { "1#铜槽下低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(2544, 1, 44, 44), "red") },
                    #endregion

                              #region 铜槽2
                    { "2#铜槽上喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(2654, 640, 100, 156), "red") },
                   
                    { "2#铜槽下喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(2900, 468, 19, 86), "red") },
                    { "2#铜槽上低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(2651, 1, 44, 44), "red") },
                    { "2#铜槽下低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(2897, 1, 44, 44), "red") },
                    #endregion

                    #region 2#导电段
                    { "2#导电段泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(3056, 640, 100, 156), "red") },
                    { "2#导电段下低液位", new 产线AlmMapVauleType(-1, new Rectangle(3121, 534, 22, 23), "red") },
                    { "2#导电段下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(3436, 510, 22, 23), "red") },
                    { "2#导电段1电流异常", new 产线AlmMapVauleType(-1, new Rectangle(3021, 260, 25, 38), "red") },
                    { "2#导电段2电流异常", new 产线AlmMapVauleType(-1, new Rectangle(3046, 260, 25, 38), "red") },
                    { "2#导电段3电流异常", new 产线AlmMapVauleType(-1, new Rectangle(3071, 260, 25, 38), "red") },
                    { "2#导电段4电流异常", new 产线AlmMapVauleType(-1, new Rectangle(3096, 260, 25, 38), "red") },
                    { "2#导电段5电流异常", new 产线AlmMapVauleType(-1, new Rectangle(3121, 260, 25, 38), "red") },

                    #endregion

                                  #region 铜槽3
                    { "3#铜槽上喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(3229, 640, 100, 156), "red") },

                    { "3#铜槽下喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(3477, 640, 100, 156), "red") },
                    { "3#铜槽上低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(3229, 1, 44, 44), "red") },
                    { "3#铜槽下低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(3470, 1, 44, 44), "red") },
                    #endregion

                                  #region 铜槽4
                    { "4#铜槽上喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(3580, 640, 100, 156), "red") },

                    { "4#铜槽下喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(3825, 640, 100, 156), "red") },
                    { "4#铜槽上低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(3578, 1, 44, 44), "red") },
                    { "4#铜槽下低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(3822, 1, 44, 44), "red") },
                    #endregion

                      #region 3#导电段
                    { "3#导电段泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(3986, 640, 100, 156), "red") },
                    { "3#导电段下低液位", new 产线AlmMapVauleType(-1, new Rectangle(4051, 531, 22, 23), "red") },
                    { "3#导电段下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(4362, 510, 22, 23), "red") },
                    { "3#导电段1电流异常", new 产线AlmMapVauleType(-1, new Rectangle(3950, 260, 25, 38), "red") },
                    { "3#导电段2电流异常", new 产线AlmMapVauleType(-1, new Rectangle(3975, 260, 25, 38), "red") },
                    { "3#导电段3电流异常", new 产线AlmMapVauleType(-1, new Rectangle(4000, 260, 25, 38), "red") },
                    { "3#导电段4电流异常", new 产线AlmMapVauleType(-1, new Rectangle(4025, 260, 25, 38), "red") },
                    { "3#导电段5电流异常", new 产线AlmMapVauleType(-1, new Rectangle(4050, 260, 25, 38), "red") },

                    #endregion

                                         #region 铜槽5
                    { "5#铜槽上喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(4157, 640, 100, 156), "red") },

                    { "5#铜槽下喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(4400,  640, 100, 156), "red") },
                    { "5#铜槽上低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(4155, 1, 44, 44), "red") },
                    { "5#铜槽下低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(4400, 1, 44, 44), "red") },
                    
                    #endregion
                                #region 铜槽6
                    { "6#铜槽上喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(4507, 640, 100, 156), "red") },
                    { "整流机冷却泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(4633, 640, 100, 156), "red") },
                    { "6#铜槽下喷变频器异常", new 产线AlmMapVauleType(-1, new Rectangle(4750, 640, 100, 156), "red") },
                    { "6#铜槽上低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(4505, 1, 44, 44), "red") },
                    { "6#铜槽下低流量偏差报警", new 产线AlmMapVauleType(-1, new Rectangle(4750, 1, 44, 44), "red") },
                    #endregion

                    #region 4#导电段
                    { "4#导电段泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(4911, 640, 100, 156), "red") },
                    { "4#导电段下低液位", new 产线AlmMapVauleType(-1, new Rectangle(4978, 531, 22, 23), "red") },
                    { "4#导电段下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(4993, 510, 22, 23), "red") },
                    { "4#导电段1电流异常", new 产线AlmMapVauleType(-1, new Rectangle(4875, 260, 25, 38), "red") },
                    { "4#导电段2电流异常", new 产线AlmMapVauleType(-1, new Rectangle(4900, 260, 25, 38), "red") },
                    { "4#导电段3电流异常", new 产线AlmMapVauleType(-1, new Rectangle(4925, 260, 25, 38), "red") },
                    { "4#导电段4电流异常", new 产线AlmMapVauleType(-1, new Rectangle(4950, 260, 25, 38), "red") },
                    { "4#导电段5电流异常", new 产线AlmMapVauleType(-1, new Rectangle(4975, 260, 25, 38), "red") },

                    #endregion

                    #region 10# 水洗
                    { "10#水洗5泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(5070, 640, 100, 156), "red") },
                    { "10#水洗5下低液位", new 产线AlmMapVauleType(-1, new Rectangle(5166, 534, 22, 23), "red") },
                    { "10#水洗5下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(5184, 510, 22, 23), "red") },

                    #endregion

                    #region 11# 水洗
                    { "11#水洗6泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(5257, 640, 100, 156), "red") },
                    { "11#水洗6下低液位", new 产线AlmMapVauleType(-1, new Rectangle(5352, 534, 22, 23), "red") },
                    { "11#水洗6下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(5368, 510, 22, 23), "red") },
                    { "11#水洗6补水电磁阀超时", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
 
                    #endregion

                    #region 12# 酸洗
                    { "12#酸洗循环泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(5452, 640, 100, 156), "red") },
                    { "12#酸洗喷流泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(5551, 640, 100, 156), "red") },
                    { "12#酸洗下低液位", new 产线AlmMapVauleType(-1, new Rectangle(5575, 534, 19, 23), "red") },
                    { "12#酸洗（上）槽低液位", new 产线AlmMapVauleType(-1, new Rectangle(5598, 168, 22, 23), "red") },
                    { "12#酸洗下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(5591, 510, 22, 23), "red") },
            
 
                    #endregion

                         
                    #region 13# 水洗
                    { "13#水洗7泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(5669, 640, 100, 156), "red") },
                    { "13#水洗7下低液位", new 产线AlmMapVauleType(-1, new Rectangle(5764, 534, 19, 86), "red") },
                    { "13#水洗7下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(5780, 470, 16, 60), "red") },

                    #endregion
                             
                    #region 14# 水洗
                    { "14#水洗8泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(5857, 640, 100, 156), "red") },
                    { "14#水洗8下低液位", new 产线AlmMapVauleType(-1, new Rectangle(5951, 468, 19, 86), "red") },
                    { "14#水洗8下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(5968, 470, 16, 60), "red") },
                    { "14#水洗9补水电磁阀超时", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
 
                    #endregion

                           
                    #region 15# 抗氧化
                    { "15#抗氧化泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(6048, 640, 100, 156), "red") },                 
                    { "15#抗氧化下低液位", new 产线AlmMapVauleType(-1, new Rectangle(6168, 468, 19, 86), "red") },
                    { "15#抗氧化下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(6185, 470, 16, 60), "red") },
                    #endregion
                               
                    #region 16# 水洗
                    { "16#水洗9泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(6266, 640, 100, 156), "red") },
                    { "16#水洗9下低液位", new 产线AlmMapVauleType(-1, new Rectangle(6360, 468, 19, 86), "red") },
                    { "16#水洗9下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(6378, 470, 16, 60), "red") },

                    #endregion

                    #region 17# 水洗
                    { "17#水洗10泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(6452, 640, 100, 156), "red") },
                    { "17#水洗10下低液位", new 产线AlmMapVauleType(-1, new Rectangle(6545, 468, 19, 86), "red") },
                    { "17#水洗10下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(6564, 470, 16, 60), "red") },
                    #endregion

                    #region 18# 水洗
                    { "18#水洗11泵浦过载", new 产线AlmMapVauleType(-1, new Rectangle(6636, 640, 100, 156), "red") },
                    { "18#水洗11下低液位", new 产线AlmMapVauleType(-1, new Rectangle(6730, 468, 19, 86), "red") },
                    { "18#水洗11下低液位预警", new 产线AlmMapVauleType(-1, new Rectangle(6750, 470, 16, 60), "red") },
              //      { "18#水洗11补水电磁阀超时", new 产线AlmMapVauleType(-1, new Rectangle(0, 0, 1, 1), "red") },
 
                    #endregion

                    #region 吹干+烘干
                    { "冷风吹干风机1过载", new 产线AlmMapVauleType(-1, new Rectangle(6800, 640, 100, 156), "red") },
                    { "冷风吹干风机2过载", new 产线AlmMapVauleType(-1, new Rectangle(6900, 640, 100, 156), "red") },
                    { "热风吹干风机1过载", new 产线AlmMapVauleType(-1, new Rectangle(7000, 640, 100, 156), "red") },
                    { "热风吹干风机2过载", new 产线AlmMapVauleType(-1, new Rectangle(7100, 640, 100, 156), "red") },
 
                    #endregion

                     #region 卷出
                    { "卷出上转轴马达过载", new 产线AlmMapVauleType(-1, new Rectangle(7322, 345, 44, 44), "red") },
                    { "卷出下转轴马达过载", new 产线AlmMapVauleType(-1, new Rectangle(7325, 560, 44, 44), "red") },                 
                    #endregion
                };
                
                foreach(var name in 产线AlmMap.Keys)
                {
                    产线AlmMap[name].context = name;

                    string key = null;
                    foreach(string kk in OmronPLC.AlarmCodes.Keys)
                    {
                        if (name == OmronPLC.AlarmCodes[kk].Content)
                        {
                            key = "C" + OmronPLC.AlarmCodes[kk].AbsAddr;
                            break;
                        }
                    }

                    if (key == null)
                    {
                        //MessageBox.Show(name);
                        //break;
                        //System.Diagnostics.Debug.Assert(false, name);
                        continue;
                    }

                    for(int i=0; i<OmronPLC.B报警.AlarmSet.Length; i++)
                    {
                        if (key == OmronPLC.B报警.AlarmSet[i].HslAddr)
                        {
                            产线AlmMap[name].index = i;
                            break;
                        }
                    }
                }
            };

           
            foreach (var key in 产线AlmMap.Keys)
            {
                    CutPicture.CutRegions.Add(
                    new CutRegion()
                    {
                        Context = key,
                        Rect = 产线AlmMap[key].rectangle,
                        Param = new Tuple<OmronData, 产线AlmMapVauleType>(OmronPLC, 产线AlmMap[key]),
                        GetCutLayer = (object param) =>
                        {
                            var plc = (param as Tuple<OmronData, 产线AlmMapVauleType>).Item1;
                            var value = (param as Tuple<OmronData, 产线AlmMapVauleType>).Item2;

                            if (value.index < 0)
                            {
                                return -1;
                            }

                            var alm = plc.B报警.AlarmSet[value.index];
                            if (alm.Value)
                            {
                                return 产线AlmLayer[value.layer];
                            }

                            return -1;
                        }
                    }
                );
            }

            int JTH = 45;
            产线TextList = new List<产线TextType>()
            {
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗1料号, rectangle = new Rectangle(266,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.除油2料号, rectangle = new Rectangle(471,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.热水洗3料号, rectangle = new Rectangle(696,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗4料号, rectangle = new Rectangle(905,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗5料号, rectangle = new Rectangle(1090,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.微蚀6料号, rectangle = new Rectangle(1294,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗7料号, rectangle = new Rectangle(1504,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗8料号, rectangle = new Rectangle(1689,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.酸浸9料号, rectangle = new Rectangle(1891,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电1, rectangle = new Rectangle(2122,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.铜槽1, rectangle = new Rectangle(2346,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电2, rectangle = new Rectangle(3049,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.铜槽2, rectangle = new Rectangle(2696,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电3, rectangle = new Rectangle(3978,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.铜槽3, rectangle = new Rectangle(3274,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电4, rectangle = new Rectangle(3978,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.铜槽4, rectangle = new Rectangle(3623,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电5, rectangle = new Rectangle(3978,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.铜槽5, rectangle = new Rectangle(4202,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电6, rectangle = new Rectangle(3978,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.铜槽6, rectangle = new Rectangle(4551,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电7, rectangle = new Rectangle(3978,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.铜槽7, rectangle = new Rectangle(4689,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电8, rectangle = new Rectangle(3978,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.铜槽8, rectangle = new Rectangle(4689,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.导电9, rectangle = new Rectangle(4905,200,75,JTH) },

                new 产线TextType(){ lh = OmronPLC.LH料号.水洗11料号, rectangle = new Rectangle(5292,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.酸洗12, rectangle = new Rectangle(5498,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗13料号, rectangle = new Rectangle(5707,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗14料号, rectangle = new Rectangle(5893,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.抗氧化15, rectangle = new Rectangle(6094,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗16料号, rectangle = new Rectangle(6299,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗17料号, rectangle = new Rectangle(6488,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.水洗18料号, rectangle = new Rectangle(6671,200,75,JTH) },
                new 产线TextType(){ lh = OmronPLC.LH料号.吹干烘干19, rectangle = new Rectangle(6866,200,75,JTH) },
            };



           // CutPicture.CutRegions.Add(
           //     new CutRegion()
           //     {
           //         Rect = new Rectangle(266, 200, 75, JTH),
           //         Param = OmronPLC.LH料号.水洗1料号,
           //         GetCutLayer = (object param) =>
           //         {
           //             var id = OmronPLC.LH料号.水洗1料号.Value;
           //                     //    var id = (Utility.HslWapper.Variable<UInt16>) param.;


           //                     if (id != 0)
           //             {
           //                 MessageBox.Show("水洗1id= ", id.ToString());
           //                 return 2;
           //             }

           //             return -1;
           //         }
           //     }
           // );

           // CutPicture.CutRegions.Add(
           //    new CutRegion()
           //    {
           //        Rect = new Rectangle(471, 200, 75, JTH),
           //        Param = OmronPLC.LH料号.除油2料号,
           //        GetCutLayer = (object param) =>
           //        {
           //            var id = OmronPLC.LH料号.除油2料号.Value;
           //            MessageBox.Show("除油2id= ",id.ToString());
           //             if (id != 0)
           //            {                        
           //                 return 2;
           //            }

           //            return -1;
           //        }
           //    }
           //);

            foreach (var iter in 产线TextList)
            {
                CutPicture.CutRegions.Add(
                    new CutRegion()
                    {
                        Rect = iter.rectangle,
                        Param = new Tuple<OmronData, Utility.HslWapper.Variable<UInt16>>(OmronPLC, iter.lh),
                        GetCutLayer = (object param) =>
                        {
                            var plc = (param as Tuple<OmronData, Utility.HslWapper.Variable<UInt16>>).Item1;
                            var id = (param as Tuple<OmronData, Utility.HslWapper.Variable<UInt16>>).Item2.Value;

                            if (id != 0)
                            {
                                if (id == plc.SL上料参数.L料号ID.Value)
                                {
                                
                                    return 1;
                                }
                                else
                                {
                                   
                                    return 2;
                                }
                            }

                            return -1;
                        }
                    }
                );

                CutPicture.TextRegions.Add(
                   new TextRegion()
                   {
                       Rect = iter.rectangle,
                       Param = iter.lh,
                       GetText = (object param) =>
                       {
                           var id = (param as Utility.HslWapper.Variable<UInt16>).Value;

                           //if (LHNameMap == null)
                           //{
                           //    LHNameMap = new Dictionary<Int64, string>();
                           //    var tttt = RecipeView.ListAll();
                           //    foreach (var recipe in tttt)
                           //    {
                           //        LHNameMap[recipe.Id] = recipe.Name;
                           //    }
                           //}

                           string str = "---";
                           if (id != 0)
                           {
                               //if (!LHNameMap.Keys.Contains(id))
                               //{
                               //    LHNameMap = new Dictionary<Int64, string>();
                               //    var tttt = RecipeView.ListAll();
                               //    foreach (var recipe in tttt)
                               //    {
                               //        LHNameMap[recipe.Id] = recipe.Name;
                               //    }
                               //}

                               //if (LHNameMap.Keys.Contains(id))
                               //{
                               //    str = LHNameMap[id];
                               //}
                               //else
                               //{
                               //    str = "未查到";
                               //}
                               str = id.ToString();
                           }
                           return new Tuple<string, Color>(str, Color.Red);
                       }
                   }
                );
            }

            CutPicture.TextRegions.Add(
                new TextRegion()
                {   // 除油温度
                    Rect = new Rectangle(465, 448, 53, 18),
                    Param = OmronPLC,
                    GetText = (object param) =>
                    {
                        var plc = param as OmronData;

                        string str = "温度:" + plc.CY除油温度.实际值.Value.ToString() + "℃";
                        Color color = Color.Black;
                        if (plc.B报警.AlarmSet[80].Value)
                        {   // 高温报警
                            color = Color.Red;
                        }
                        if (plc.B报警.AlarmSet[96].Value)
                        {   // 低温报警
                            color = Color.Blue;
                        }

                        return new Tuple<string, Color>(str, color);
                    }
                }
            );

            CutPicture.TextRegions.Add(
                new TextRegion()
                {   // 热水洗
                    Rect = new Rectangle(703, 448, 53, 18),
                    Param = OmronPLC,
                    GetText = (object param) =>
                    {
                        var plc = param as OmronData;

                        string str = "温度:" + plc.RS热水洗温度.实际值.Value.ToString() + "℃";
                        Color color = Color.Black;
                        if (plc.B报警.AlarmSet[81].Value)
                        {   // 高温报警
                            color = Color.Red;
                        }
                        if (plc.B报警.AlarmSet[97].Value)
                        {   // 低温报警
                            color = Color.Blue;
                        }

                        return new Tuple<string, Color>(str, color);
                    }
                }
            );

            CutPicture.TextRegions.Add(
                new TextRegion()
                {   // 微蚀
                    Rect = new Rectangle(1288, 448, 53, 18),
                    Param = OmronPLC,
                    GetText = (object param) =>
                    {
                        var plc = param as OmronData;

                        string str = "温度:" + plc.RS热水洗温度.实际值.Value.ToString() + "℃";
                        Color color = Color.Black;
                        if (plc.B报警.AlarmSet[85].Value)
                        {   // 高温报警
                            color = Color.Red;
                        }
                        if (plc.B报警.AlarmSet[101].Value)
                        {   // 低温报警
                            color = Color.Blue;
                        }

                        return new Tuple<string, Color>(str, color);
                    }
                }
            );


            pBox1.Image = CutPicture.Get();
        }

        /// <summary>
        /// 初始化上料区
        /// </summary>
        /// <param name="grid"></param>
        private void Init产线布局(FlexCell.Grid grid)
        {
            grid.AutoRedraw = false;


            // 设置行数/列数
            grid.Rows = 5;
            grid.Cols = N_前处理段 + Config.镀铜槽数 + N_后处理段 + 1;


            //这个包围区间要减1
            grid.Range(1, 1, grid.Rows - 1, grid.Cols - 1).Alignment = FlexCell.AlignmentEnum.CenterCenter;
            grid.Range(2, 2, 2, grid.Cols - 1).Alignment = FlexCell.AlignmentEnum.CenterCenter;

            //去除首行首列
            grid.Row(0).Visible = false;
            grid.Column(0).Visible = false;

            //合并单元格
            //前处理段
            grid.Range(1, 1, 1, N_前处理段).Merge();
            grid.Range(1, N_前处理段 + 1, 1, N_前处理段 + Config.镀铜槽数).Merge();
            grid.Range(1, grid.Cols - N_后处理段, 1, grid.Cols - 1).Merge();




            for (int i = 1; i <= N_前处理段; i++)
            {
                grid.Range(2, i, 3, i).Merge();
             
            }
            for (int i = grid.Cols - N_后处理段; i < grid.Cols; i++)
            {
                grid.Range(2, i, 3, i).Merge();
           
            }


            // 设置行高/列宽
            for (int i = 1; i < grid.Rows; i++)
                grid.Row(i).Height = (short)(grid.Height / 8);

            grid.Row(2).Height = (short)(2 * grid.Row(1).Height);
            grid.Row(3).Height = (short)(2 * grid.Row(1).Height);
            grid.Row(4).Height = (short)(2 * grid.Row(1).Height);


            //前处理段

            for (int i = 1; i <= N_前处理段; i++)
            {
                grid.Column(i).Width = 35;
            }

            //后处理段
            for (int i = grid.Cols - N_后处理段; i < grid.Cols; i++)
            {
                grid.Column(i).Width = 35;
            }

            for (int i = N_前处理段 + 1; i < N_前处理段 + 1 + Config.镀铜槽数; i++)
            {
                grid.Column(i).Width = (short)((grid.Width - 13 * 30) / (Config.镀铜槽数 + 1));
            }

            //前处理段
            for (int i = 1; i <= N_前处理段; i++)
                grid.Cell(2, i).WrapText = true;

            //后处理段
            for (int i = grid.Cols - N_后处理段; i < grid.Cols; i++)
                grid.Cell(2, i).WrapText = true;

            // 设置单元格文字、背景色
            grid.Cell(1, 1).Text = "前处理段";
            grid.Cell(1, 1).BackColor = Color.FromArgb(127, 255, 255);
            grid.Cell(1, N_前处理段 + 1).Text = "镀铜段";
            grid.Cell(1, N_前处理段 + 1).BackColor = Color.FromArgb(255, 255, 23);
            grid.Cell(1, grid.Cols - N_后处理段).Text = "后处理段";
            grid.Cell(1, grid.Cols - N_后处理段).BackColor = Color.FromArgb(127, 255, 255);

            int col = 1;        
            grid.Cell(2, col++).Text = "\n上\r\n料";
            grid.Cell(2, col).BackColor = Color.FromArgb(128, 255, 255);
            grid.Cell(2, col++).Text = "\n除\r\n油\r\n1";
            grid.Cell(2, col).BackColor = Color.FromArgb(128, 255, 128);
            grid.Cell(2, col++).Text = "\n热\r\n水\r\n洗\r\n2";
            grid.Cell(2, col).BackColor = Color.FromArgb(153, 180, 209);
            grid.Cell(2, col++).Text = "\n水\r\n洗\r\n3";
            grid.Cell(2, col).BackColor = Color.FromArgb(153, 180, 209);
            grid.Cell(2, col++).Text = "\n水\r\n洗\r\n4";
            grid.Cell(2, col).BackColor = Color.FromArgb(255, 192, 128);
            grid.Cell(2, col++).Text = "\n微\r\n蚀\r\n5";
            grid.Cell(2, col).BackColor = Color.FromArgb(153, 180, 209);
            grid.Cell(2, col++).Text = "\n水\r\n洗\r\n6";
            grid.Cell(2, col).BackColor = Color.FromArgb(153, 180, 209);
            grid.Cell(2, col++).Text = "\n水\r\n洗\r\n7";
            grid.Cell(2, col).BackColor = Color.FromArgb(255, 128, 128);
            grid.Cell(2, col++).Text = "\n预\r\n浸\r\n8";       
            for (int i = 0; i < Config.镀铜槽数; i++)
            {
                grid.Cell(2, col).BackColor = Color.FromArgb(255, 255, 192);
                grid.Cell(2, col++).Text = "\n镀\r\n铜\r\n" + (i + 1).ToString();
            }
                

            grid.Cell(2, col).BackColor = Color.FromArgb(153, 180, 209);
            grid.Cell(2, col++).Text = "\n水\r\n洗\r\n9";
            grid.Cell(2, col).BackColor = Color.FromArgb(153, 180, 209);
            grid.Cell(2, col++).Text = "\n水\r\n洗\r\n10";
            grid.Cell(2, col).BackColor = Color.FromArgb(153, 180, 209);
            grid.Cell(2, col++).Text = "\n水\r\n洗\r\n11";
            grid.Cell(2, col++).Text = "\n下\r\n料\r\n";
     
            //设置单元格格式
            //字体
            //  grid1.Cell(1, 1).FontSize = 11;

            grid.AutoRedraw = true;
            grid.Refresh();
        }

        private Dictionary<long, string> GetDictSL()
        {
            var dict = new Dictionary<long, string>();
            var list = RecipeView.ListAll();
            foreach(var iter in list)
            {
                dict[iter.Id] = iter.Name;
            }
            return dict;
        }

        private string GetLHName(int key)
        {
            var recipe = RecipeView.SelectById(key);
            if (recipe != null)
            {
                return recipe.Name;
            }
            return key.ToString();
        }

        ///// <summary>
        ///// 刷新上料区未完成
        ///// </summary>
        //private void Update产线(FlexCell.Grid grid)
        //{
        //    grid.AutoRedraw = false;


        //    #region//显示有料进度
        //    int col = 2;
        //    if (OmronPLC.LH料号.除油有料.Value)
        //    {           
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    if (OmronPLC.LH料号.热水洗2有料.Value)
        //    {
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
             
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    if (OmronPLC.LH料号.水洗3有料.Value)
        //    {
             
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
              
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    if ( OmronPLC.LH料号.水洗4有料.Value)
        //    {
               
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
              
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }


        //    if ( OmronPLC.LH料号.微蚀5有料.Value)
        //    {         
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
          
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    if ( OmronPLC.LH料号.水洗6有料.Value)
        //    {
                
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
              
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    if (OmronPLC.LH料号.水洗7有料.Value)
        //    {
                
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
              
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    if ( OmronPLC.LH料号.酸浸8有料.Value)
        //    {
                
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
            
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    //这个地方要考虑下
        //    for (int i = 0; i < Config.镀铜槽数; i++)
        //    {
        //        if ( OmronPLC.LH料号.镀铜槽有料A[i].Value)
        //        {
                  
        //            grid.Cell(3, col).BackColor = Color.FromArgb(192, 64, 0);
        //        }
        //        else
        //        {
                  
        //            grid.Cell(3, col).BackColor = Color.White;
        //        }


        //        if (OmronPLC.LH料号.镀铜槽有料B[i].Value)
        //        {
        //            grid.Cell(4, col).BackColor = Color.FromArgb(192, 64, 0);
        //        }
        //        else
        //        {

        //            grid.Cell(4, col).BackColor = Color.White;
        //        }

        //        col++;
        //    }

        //    if ( OmronPLC.LH料号.水洗9有料.Value)
        //    {
               
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
               
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    if (OmronPLC.LH料号.水洗10有料.Value)
        //    {
                
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
    
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }

        //    if ( OmronPLC.LH料号.水洗11有料.Value)
        //    {
              
        //        grid.Cell(4, col++).BackColor = Color.FromArgb(192, 64, 0);
        //    }
        //    else
        //    {
               
        //        grid.Cell(4, col++).BackColor = Color.White;
        //    }
        //    #endregion

        //    col = 2;
        //    #region 上料区显示料号
        //    if (OmronPLC.LH料号.除油料号.Value > 0)
        //    {

        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.除油料号.Value);
        //        //   grid.Cell(3, col++).Text = OmronPLC.LH料号.除油料号.Value.ToString();

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }

        //    if (OmronPLC.LH料号.热水洗2料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.热水洗2料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }

        //    if (OmronPLC.LH料号.水洗3料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.水洗3料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }

        //    if (OmronPLC.LH料号.水洗4料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.水洗4料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }


        //    if (OmronPLC.LH料号.微蚀5料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.微蚀5料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }

        //    if (OmronPLC.LH料号.水洗6料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.水洗6料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }

        //    if (OmronPLC.LH料号.水洗7料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.水洗7料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }

        //    if (OmronPLC.LH料号.酸浸8料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.酸浸8料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }


        //    for (int i = 0; i < Config.镀铜槽数; i++)
        //    {
        //        if (OmronPLC.LH料号.镀铜槽料号A[i].Value > 0)
        //        {
        //            grid.Cell(3, col).Text = GetLHName(OmronPLC.LH料号.镀铜槽料号A[i].Value);

        //        }
        //        else
        //        {
        //            grid.Cell(3, col).Text = "";

        //        }

        //        if (OmronPLC.LH料号.镀铜槽料号B[i].Value > 0)
        //        {
        //            grid.Cell(4, col).Text = GetLHName(OmronPLC.LH料号.镀铜槽料号B[i].Value);

        //        }
        //        else
        //        {
        //            grid.Cell(4, col).Text = "";

        //        }

        //        col++;
        //    }

        //    if (OmronPLC.LH料号.水洗9料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.水洗9料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }

        //    if (OmronPLC.LH料号.水洗10料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.水洗10料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }

        //    if (OmronPLC.LH料号.水洗11料号.Value > 0)
        //    {
        //        grid.Cell(4, col++).Text = GetLHName(OmronPLC.LH料号.水洗11料号.Value);

        //    }
        //    else
        //    {
        //        grid.Cell(4, col++).Text = "";

        //    }
        //    #endregion

        //    grid.AutoRedraw = true;
        //    grid.Refresh();
        //}

        /// <summary>
        /// 镀铜槽数据表初始化
        /// </summary>
        private void Init镀铜槽数据表(FlexCell.Grid grid)
        {
            grid.AutoRedraw = false;
            grid.ExtendLastCol = false;

            // 设置行数/列数
            grid.Rows = KorbeRTR.Config.镀铜槽数 + 3;
            grid.Cols = 11;

            for (int i = 1; i < grid.Cols; i++)
            {
                grid.Column(i).Width = (short)(grid.Width / (grid.Cols - 1));
            }

         

            //这个包围区间要减1
            grid.Range(0, 0, grid.Rows - 1, grid.Cols - 1).Alignment = FlexCell.AlignmentEnum.CenterCenter;

            grid.Row(0).Visible = false;
            grid.Column(0).Visible = false;

            int col = 1;
            grid.Range(1, col, 1, col + 1).Merge();
            grid.Cell(1, col).Text = "工艺";
            col = 3;
            grid.Range(1, col, 1, col + 1).Merge();
            grid.Cell(1, col).Text = "上整流机";
            col = 5;
            grid.Range(1, col, 1, col + 1).Merge();
            grid.Cell(1, col).Text = "下整流机";
            col = 7;           
            grid.Range(1, col, 1, col + 1).Merge();
            grid.Cell(1, col).Text = "上喷流频率";
            col = 9;
            grid.Range(1, col, 1, col + 1).Merge();
            grid.Cell(1, col).Text = "下喷流频率";

            grid.Cell(2, 1).Text = "编号";
            grid.Cell(2, 2).Text = "槽名";
            for (int i = 3; i < 11; i += 2)
            {
                grid.Cell(2, i).Text = "设定";
                grid.Cell(2, i + 1).Text = "实际";
            }

            grid.AutoRedraw = true;
            grid.Refresh();
        }

        /// <summary>
        /// 更新数据表信息
        /// </summary>
        /// <param name="grid"></param>
        public void Update镀铜槽数据表(FlexCell.Grid grid)
        {
            grid.AutoRedraw = false;

            for (int i = 0; i < Config.镀铜槽数; i++)
            {
                int row = i + 3;
                int col = 1;

                grid.Cell(row, col++).Text = (i + 1).ToString();
                grid.Cell(row, col++).Text = "镀铜" + grid.Cell(row, 1).Text;

                grid.Cell(row, col++).Text = OmronPLC.D镀铜槽状态[i].C面设定电流[0].Value.ToString();
                grid.Cell(row, col++).Text = OmronPLC.D镀铜槽状态[i].C面实际电流[0].Value.ToString();

                grid.Cell(row, col++).Text = OmronPLC.D镀铜槽状态[i].S面设定电流[0].Value.ToString();
                grid.Cell(row, col++).Text = OmronPLC.D镀铜槽状态[i].S面实际电流[0].Value.ToString();

            
         


                grid.Cell(row, col++).Text = OmronPLC.D镀铜槽状态[i].设定显示频率[0].Value.ToString();
                grid.Cell(row, col++).Text = OmronPLC.D镀铜槽状态[i].实际频率[0].Value.ToString();

                grid.Cell(row, col++).Text = OmronPLC.D镀铜槽状态[i].设定显示频率[1].Value.ToString();
                grid.Cell(row, col++).Text = OmronPLC.D镀铜槽状态[i].实际频率[1].Value.ToString();
            }

            grid.AutoRedraw = true;
            grid.Refresh();
        }

        private void Init故障表(FlexCell.Grid grid)
        {
            grid.AutoRedraw = false;
            grid.ExtendLastCol = true;
            grid.DisplayRowNumber = true;
            //  AlarmRecordView.ListAll();
            // 设置行数/列数

            grid.Cols = 3;

            grid.Column(0).Width = 30;
            grid.Column(1).Width = 130;
            grid.Rows = 1;

            grid.Cell(0, 0).Text = "序号";
            grid.Cell(0, 1).Text = "时间";
            grid.Cell(0, 2).Text = "故障描述";

            grid.AutoRedraw = true;
            grid.Refresh();

        }

        /// <summary>
        /// 更新故障列表
        /// </summary>
        /// <param name="grid"></param>
        private void Update故障表(FlexCell.Grid grid)
        {
            if (OmronPLC.AlarmDict == null) return;

            grid.AutoRedraw = false;

            var list = OmronPLC.AlarmDict.Values.ToList();
            list.Sort((a, b) => b.StartTime.CompareTo(a.StartTime));

            grid.Rows = list.Count + 1;

            for (int i = 0; i < list.Count; i++)
            {
                grid.Cell(i + 1, 1).Text = list[i].StartTime.ToString();
                grid.Cell(i + 1, 2).Text = list[i].Content;

            }
            grid.AutoRedraw = true;
            grid.Refresh();
        }

        private void Initw温度控制表(FlexCell.Grid grid)
        {
            string line = ConfigurationManager.AppSettings["LINE"];

            //Grid1设置
            grid.AutoRedraw = false;
            grid.ExtendLastCol = false;

            // 设置行数/列数
            grid.Rows = 10;
            grid.Cols = 8;

            //这个包围区间要减1
            grid.Range(0, 0, grid.Rows - 1, grid.Cols - 1).Alignment = FlexCell.AlignmentEnum.CenterCenter;

            grid.Column(0).Visible = false;
            grid.Column(1).Width = 140;
            // 设置单元格文字
            int col = 1;
            grid.Cell(0, col++).Text = "工艺";
            grid.Cell(0, col++).Text = "超温警报";
            grid.Cell(0, col++).Text = "低温警报";
            grid.Cell(0, col++).Text = "设定温度";
            grid.Cell(0, col++).Text = "实际温度";
            grid.Cell(0, col++).Text = "正补偿";
            grid.Cell(0, col++).Text = "负补偿";

            int row = 1;
            grid.Cell(row++, 1).Text = "除油";
            grid.Cell(row++, 1).Text = "热水洗";
            grid.Cell(row++, 1).Text = "整流机冷却";
       
            grid.Cell(row++, 1).Text = "镀铜";
            grid.Cell(row++, 1).Text = "6#微蚀";
   
            grid.Cell(row++, 1).Text = "烘干加热";
            grid.Cell(row++, 1).Text = "12#微蚀";
            grid.Cell(row++, 1).Text = "抗氧化";
            grid.Cell(row++, 1).Text = "热水槽";

            grid.Column(2).CellType = FlexCell.CellTypeEnum.Button;
            grid.Column(3).CellType = FlexCell.CellTypeEnum.Button;
            grid.Column(4).CellType = FlexCell.CellTypeEnum.Button;

            grid.Column(6).CellType = FlexCell.CellTypeEnum.Button;
            grid.Column(7).CellType = FlexCell.CellTypeEnum.Button;

            grid.AutoRedraw = true;
            grid.Refresh();
        }
        public OmronData.TemperatureParams[] Temperatures = new OmronData.TemperatureParams[]
        {
            FormMainWindow.OmronPLC.CY除油温度,
            FormMainWindow.OmronPLC.RS热水洗温度,
            FormMainWindow.OmronPLC.ZL整流机冷却温度,
     
            FormMainWindow.OmronPLC.DT镀铜温度,
            FormMainWindow.OmronPLC.WS微蚀温度,
     
            FormMainWindow.OmronPLC.HG烘干加热温度,
            FormMainWindow.OmronPLC.SJ酸浸温度,
            FormMainWindow.OmronPLC.KYH抗氧化槽温度,
            FormMainWindow.OmronPLC.RS热水槽温度,
        };

        private void Updatew温度表(FlexCell.Grid grid)
        {
            grid.AutoRedraw = false;

            int row = 0;
            for (int i = 0; i < Temperatures.Length; i++)
            {
                var temp = Temperatures[i];

                row = i + 1;

                grid.Cell(row, 2).Text = temp.超温.Value.ToString();
                grid.Cell(row, 3).Text = temp.低温.Value.ToString();
                grid.Cell(row, 4).Text = temp.设定值.Value.ToString();
                grid.Cell(row, 5).Text = temp.实际值.Value.ToString();
                grid.Cell(row, 6).Text = temp.正补偿.Value.ToString();
                grid.Cell(row, 7).Text = temp.负补偿.Value.ToString();
            }

     

            grid.AutoRedraw = true;
            grid.Refresh();
        }

        private void Init水洗压力表(FlexCell.Grid grid)
        {
            grid.AutoRedraw = false;
            grid.ExtendLastCol = false;
            grid.DisplayRowNumber = true;

            // 设置行数/列数
            grid.Rows = 1 + 14 + 3;
            grid.Cols = 1 + 4 * 2;

            //这个包围区间要减1
            grid.Range(0, 0, grid.Rows - 1, grid.Cols - 1).Alignment = FlexCell.AlignmentEnum.CenterCenter;

            grid.Row(0).Visible = true;
            grid.Column(0).Visible = true;

            int col = 1;
            grid.Cell(0, col++).Text = "名称";
            grid.Cell(0, col++).Text = "压力";
            grid.Cell(0, col++).Text = "上限";
            grid.Cell(0, col++).Text = "下限";

            grid.Cell(0, col++).Text = "名称";
            grid.Cell(0, col++).Text = "压力";
            grid.Cell(0, col++).Text = "上限";
            grid.Cell(0, col++).Text = "下限";

            int row = 1;
            grid.Cell(row++, 1).Text = "1#水洗1";
            grid.Cell(row++, 1).Text = "1#水洗2";

            grid.Cell(row++, 1).Text = "4#水洗1";
            grid.Cell(row++, 1).Text = "4#水洗2";

            grid.Cell(row++, 1).Text = "5#水洗1";
            grid.Cell(row++, 1).Text = "5#水洗2";

            grid.Cell(row++, 1).Text = "7#水洗1";
            grid.Cell(row++, 1).Text = "7#水洗2";

            grid.Cell(row++, 1).Text = "8#水洗1";
            grid.Cell(row++, 1).Text = "8#水洗2";

            grid.Cell(row++, 1).Text = "10#水洗1";
            grid.Cell(row++, 1).Text = "10#水洗2";

            grid.Cell(row++, 1).Text = "11#水洗1";
            grid.Cell(row++, 1).Text = "11#水洗2";

            row = 1;
            grid.Cell(row++, 5).Text = "13#水洗1";
            grid.Cell(row++, 5).Text = "13#水洗2";

            grid.Cell(row++, 5).Text = "14#水洗1";
            grid.Cell(row++, 5).Text = "14#水洗2";

            grid.Cell(row++, 5).Text = "15#水洗1";
            grid.Cell(row++, 5).Text = "15#水洗2";

            grid.Cell(row++, 5).Text = "16#水洗1";
            grid.Cell(row++, 5).Text = "16#水洗2";

            grid.Cell(row++, 5).Text = "17#水洗1";
            grid.Cell(row++, 5).Text = "17#水洗2";

            grid.Cell(row++, 5).Text = "18#水洗1";
            grid.Cell(row++, 5).Text = "18#水洗2";

            grid.Cell(row++, 5).Text = "2#除油流量";

            grid.Cell(row++, 5).Text = "3#水洗流量";
            grid.Cell(row++, 5).Text = "6#微蚀流量";

            grid.Cell(row++, 5).Text = "9#预浸流量";
            grid.Cell(row++, 5).Text = "12#酸洗流量";

            grid.Column(1).Locked = true;
            grid.Column(2).Locked = true;

            grid.Column(5).Locked = true;
            grid.Column(6).Locked = true;

            grid.Column(3).CellType = FlexCell.CellTypeEnum.Button;
            grid.Column(7).CellType = FlexCell.CellTypeEnum.Button;

            grid.Column(4).CellType = FlexCell.CellTypeEnum.Button;
            grid.Column(8).CellType = FlexCell.CellTypeEnum.Button;

            grid.AutoRedraw = true;
            grid.Refresh();
        }

        private void Update水洗压力表(FlexCell.Grid grid)
        {
            grid.AutoRedraw = false;

            #region 压力值
            int row = 1;
            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No1水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No1水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No4水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No4水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No5水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No5水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No7水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No7水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No8水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No8水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No10水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No10水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No11水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 2).Text = OmronPLC.SXYL水洗压力.No11水洗压力.压力值[1].Value.ToString("F2");

            row = 1;
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No13水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No13水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No14水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No14水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No15水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No15水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No16水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No16水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No17水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No17水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No18水洗压力.压力值[0].Value.ToString("F2");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.No18水洗压力.压力值[1].Value.ToString("F2");

            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.除油2流量.Value.ToString("F1");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.水洗3流量.Value.ToString("F1");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.微蚀6流量.Value.ToString("F1");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.预浸9流量.Value.ToString("F1");
            grid.Cell(row++, 6).Text = OmronPLC.SXYL水洗压力.酸洗12流量.Value.ToString("F1");
            #endregion

            #region 上限
            row = 1;
            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No1水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No1水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No4水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No4水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No5水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No5水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No7水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No7水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No8水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No8水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No10水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No10水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No11水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 3).Text = OmronPLC.SXYL水洗压力.No11水洗压力.上限[1].Value.ToString("F2");

            row = 1;
            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No13水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No13水洗压力.上限[1].Value.ToString("F2");

                             
            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No14水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No14水洗压力.上限[1].Value.ToString("F2");
                             

            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No15水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No15水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No16水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No16水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No17水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No17水洗压力.上限[1].Value.ToString("F2");

            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No18水洗压力.上限[0].Value.ToString("F2");
            grid.Cell(row++, 7).Text = OmronPLC.SXYL水洗压力.No18水洗压力.上限[1].Value.ToString("F2");
            #endregion

            #region 下限
            row = 1;
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No1水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No1水洗压力.下限[1].Value.ToString("F2");

                             
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No4水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No4水洗压力.下限[1].Value.ToString("F2");
                             
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No5水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No5水洗压力.下限[1].Value.ToString("F2");
                             
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No7水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No7水洗压力.下限[1].Value.ToString("F2");
                             
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No8水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No8水洗压力.下限[1].Value.ToString("F2");
                            
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No10水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No10水洗压力.下限[1].Value.ToString("F2");
                             

            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No11水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 4).Text = OmronPLC.SXYL水洗压力.No11水洗压力.下限[1].Value.ToString("F2");

            row = 1;
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No13水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No13水洗压力.下限[1].Value.ToString("F2");

                             
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No14水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No14水洗压力.下限[1].Value.ToString("F2");
                             
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No15水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No15水洗压力.下限[1].Value.ToString("F2");
                             
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No16水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No16水洗压力.下限[1].Value.ToString("F2");
                             
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No17水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No17水洗压力.下限[1].Value.ToString("F2");
                             

            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No18水洗压力.下限[0].Value.ToString("F2");
            grid.Cell(row++, 8).Text = OmronPLC.SXYL水洗压力.No18水洗压力.下限[1].Value.ToString("F2");
            #endregion

            grid.Range(0, 0, grid.Rows - 1, grid.Cols - 1).ForeColor = Color.Black;

            grid.AutoRedraw = true;
            grid.Refresh();
        }

        private void Grid水洗压力_ButtonClick(object Sender, FlexCell.Grid.ButtonClickEventArgs e)
        {
            int row = Math.Max(1, Math.Min(e.Row, Grid水洗压力.Rows - 1));
            int col = Math.Max(1, Math.Min(e.Col, Grid水洗压力.Cols - 1));

            string name = "";
            switch(e.Col)
            {
                case 3:
                case 7:
                    name = Grid水洗压力.Cell(row, e.Col - 2).Text + "上限";
                    break;

                case 4:
                case 8:
                    name = Grid水洗压力.Cell(row, e.Col - 3).Text + "下限";
                    break;

                default:
                    return;
            }

            int slot = (int)name.Split('#')[0].ToInt();

            string unit = "kgf/cm2";
            double min = 0;
            double max = 1;

            string msg = string.Format("请输入'{0}':\n(范围:{1}-{2},单位:{3})", name, min, max, unit);

            bool bl = CheckForm(typeof(FormInfo).Name);
            if (!bl)
            {
                FormInfo formInfo = new FormInfo(msg, min, max);
                //   formLogin.MdiParent = this;
                formInfo.ShowDialog();
                if (formInfo.ok)
                {
                    var tp = OmronPLC.SXYL水洗压力.GetType();
                    var fi = tp.GetField(string.Format("No{0}水洗压力", slot), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                    var m = fi.GetValue(OmronPLC.SXYL水洗压力) as Models.OmronData.Type水洗压力.Type槽水洗压力;

                    switch (e.Col)
                    {
                        case 3:
                        case 7:
                            m.上限[1 - (e.Row % 2)].Value = formInfo.input.ToDouble();
                            break;

                        case 4:
                        case 8:
                            m.下限[1 - (e.Row % 2)].Value = formInfo.input.ToDouble();
                            break;

                        default:
                            return;
                    }

                    Grid水洗压力.Cell(e.Row, e.Col).Text = formInfo.input;
                    Grid水洗压力.Cell(e.Row, e.Col).ForeColor = Color.Red;
                }
            }
        }

        /// <summary>
        /// 载入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormMainWindow_Load(object sender, EventArgs e)
        {
            //初始化界面按键使能情况
            SetBtnDisEnable();


            tabPage2.Parent = null;
            TabPage整流机.Parent = null;
            this.BackgroundImage = Image.FromFile(BackImage);

            Combo卷入工位.SelectedIndex = 0;
            Combo卷出工位.SelectedIndex = 0;

            //同步开启数据
            OmronPLC.SyncStart();

            //Grid1设置 上料-下料区
            //     Init产线布局(grid产线);

            Init镀铜槽数据表(grid镀铜数据);

            Init故障表(grid故障描述表);

            Initw温度控制表(gridw温度控制);


            Init产线示意图();

            Init水洗压力表(Grid水洗压力);

            //定时器里面各种状态刷新       
            timerRefresh.Enabled = true;
        }

        private void setBJ步进手动使能()
        {
            //btn步进前进1.Enabled = true;
            //btn步进前进2.Enabled = true;
            //btn步进后退1.Enabled = true;
            //btn步进后退2.Enabled = true;
            //btn回原点.Enabled = true;
        }
        private void setBJ步进手动不使能()
        {
            //btn步进前进1.Enabled = false;
            //btn步进前进2.Enabled = false;
            //btn步进后退1.Enabled = false;
            //btn步进后退2.Enabled = false;
            //btn回原点.Enabled = false;
        }

        public int count = 0;

        private Bitmap  picture;
        private void RefreahImage()
        {
            picture = CutPicture.Get();

            if (InvokeRequired)
            {
                this.Invoke(
                    new Action(()=>
                    {
                        pBox1.Image = picture;
                    })
                );
            }
            else
            {
                pBox1.Image = picture;
            }
        }

        /// <summary>
        /// UI刷新定时器
        /// </summary>
        private void timerRefresh_Tick(object sender, EventArgs e)
        {
            //每次打开程序时先打开一次登录窗口
            if (!startLogin)
            {
                startLogin = true;
                tsmLogin_Click(sender, e);
            }

            var gl = Global.GetInstance();

            //状态栏刷新
            this.tsslblTimer.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            tsslblPath.Text = "PLC:" + OmronPLC.ip + ":" + OmronPLC.port.ToString();

            tsslblNumber.Text = "上料片数:" + OmronPLC.SL上料片数.Value.ToString() + "; 下料片数:" + OmronPLC.XL下料片数.Value.ToString();

            if (Global.LoginFlag)
            {
                
            }
            else
            {
                tsslblUserInfo.Text = "操作员:";
                SetBtnDisEnable();
            }

            if (OmronPLC.WS维修保养开关状态.Value != 0)
            {
                try
                {
                    
                    bool bl = CheckForm(typeof(FormSBWX).Name);
                    if (!bl)
                    {
                        FormSBWX form = new FormSBWX();
                        form.ShowDialog();
                    }
                   
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
                }
            }

            //在线
            {
                tsslblStatus.Text = OmronPLC.Online ? string.Format("在线({0:N0}ms)", OmronPLC.CommTime.TotalMilliseconds) : "脱机";
            }

            

            //上料区料号刷新
            if ((DateTime.Now - T产线状态刷新).TotalMilliseconds > 5000)
            {
                T产线状态刷新 = DateTime.Now;
                //      Update产线(grid产线);

                //Task.Run(
                //    () =>
                //    {
                //        RefreahImage();
                //    }
                //);

                var lhset = new Dictionary<int, int>();
                foreach(var iter in 产线TextList)
                {
                    lhset[iter.lh.Value] = iter.lh.Value;
                }

                txtDQ当前料号.Text = "";
                txtQ前一个料号.Text = "";

                foreach(var id in lhset.Keys)
                {
                    if (id != 0)
                    {
                        if (id == OmronPLC.SL上料参数.L料号ID)
                        {
                            txtDQ当前料号.Text = id.ToString();
                        }
                        else
                        {
                            txtQ前一个料号.Text = id.ToString();
                        }
                    }
                }

                var watch = new System.Diagnostics.Stopwatch();
                watch.Start();
                var pic = CutPicture.Get();
                watch.Stop();
                Console.WriteLine("Get" + watch.Elapsed.TotalMilliseconds);

                watch.Reset();
                watch.Start();
                pBox1.Image = pic;
                watch.Stop();
                Console.WriteLine("Image" + watch.Elapsed.TotalMilliseconds);
            }

            

            //镀铜数据刷新
            if ((DateTime.Now - T铜槽数据刷新).TotalMilliseconds > 2000)
            {
                T铜槽数据刷新 = DateTime.Now;
                Update镀铜槽数据表(grid镀铜数据);
            }

            // 故障记录刷新           
            {
                Update故障表(grid故障描述表);
            }

            //温度控制表数据刷新
            {
                Updatew温度表(gridw温度控制);
            }

            if ((DateTime.Now - T水洗压力刷新).TotalMilliseconds > 3000)
            {
                T水洗压力刷新 = DateTime.Now;
                Update水洗压力表(Grid水洗压力);
            }

            var ColorON = Color.Lime;
            var ColorOFF = Color.FromArgb(225,225,225);

            var LampColorON = Color.Lime;
            var LampColorOFF = Color.Gray;
            var lampColorException = Color.Yellow;
            var LampColorAlarm = Color.Red;


            #region 上料区刷新
            txt实际线速毫米每秒.Text = OmronPLC.SJ实际线速.Value.ToString();
            lamp允许切换料号.LanternBackground = OmronPLC.Flag允许切换料号.Value ? LampColorON : lampColorException;
            lamp允许切换线速.LanternBackground = OmronPLC.Flag允许切换线速.Value ? LampColorON : lampColorException;
            #endregion


            #region 上料参数刷新
            {
                if (OmronPLC.CommTime.TotalMilliseconds > 0 && Global.GetInstance().CurrentUser != null)
                {
                    if (reFresh料号)
                    {
                        //初始时候读取PLC中料号ID，然后筛选出recipe，再刷新
                        if (OmronPLC.SL上料参数.L料号ID.Value > 0)
                        {
                            var recipe = RecipeView.SelectById(OmronPLC.SL上料参数.L料号ID.Value);
                            if (recipe != null)
                            {
                                gl.CurrentRecipeView = recipe;
                                FillRecipe(recipe);
                                //txt料号.BackColor = Color.Lime;
                            }
                        }
                        reFresh料号 = false;
                    }
                }

                //料号记录里面单击设置
                if (gl.FlagRefreshRecipe)
                {
                    gl.FlagRefreshRecipe = false;

                    if (gl.CurrentRecipeView != null)
                    {
                        FillRecipe(gl.CurrentRecipeView);
                    }
                }

                if (gl.CurrentRecipeView == null)
                {
                    txt料号.BackColor = Color.White;
                }
                else
                {
                    if (OmronPLC.SL上料参数.L料号ID.Value == gl.CurrentRecipeView.Id)
                    {
                        txt料号.BackColor = Color.Lime;
                    }
                    else
                    {
                        txt料号.BackColor = Color.Yellow;
                    }
                }
            }

            #endregion



            #region 泵浦控制界面 
            BtnGL隔离水洗.BackColor = OmronPLC.GetGL隔离水洗.Value ? ColorON : ColorOFF;
            BtnCY除油喷淋.BackColor = OmronPLC.GetCY除油喷淋.Value ? ColorON : ColorOFF;
            BtnCY除油循环.BackColor = OmronPLC.GetCY除油循环.Value ? ColorON : ColorOFF;
            BtnRS热水洗喷淋.BackColor = OmronPLC.GetRS热水洗喷淋.Value ? ColorON : ColorOFF;
            BtnRS热水洗循环.BackColor = OmronPLC.GetRS热水洗循环.Value ? ColorON : ColorOFF;
            BtnSX水洗1.BackColor = OmronPLC.GetSX水洗1.Value ? ColorON : ColorOFF;
            BtnSX水洗2.BackColor = OmronPLC.GetSX水洗2.Value ? ColorON : ColorOFF;

            BtnSJR水加热循环泵.BackColor = OmronPLC.GetSJR水加热循环泵.Value ? ColorON : ColorOFF;
            //BtnDQ铜粉添加打气风机.BackColor = OmronPLC.GetDQ打气开关.Value ? ColorON : ColorOFF;

            BtnWSPL微蚀喷淋.BackColor = OmronPLC.GetWS微蚀喷淋.Value ? ColorON : ColorOFF;
            BtnWSXH微蚀循环.BackColor = OmronPLC.GetWS微蚀循环.Value ? ColorON : ColorOFF;
            BtnSX水洗3.BackColor = OmronPLC.GetSX水洗3.Value ? ColorON : ColorOFF;
            BtnSX水洗4.BackColor = OmronPLC.GetSX水洗4.Value ? ColorON : ColorOFF;

            BtnYJ预浸喷淋.BackColor = OmronPLC.GetSJ酸浸喷淋.Value ? ColorON : ColorOFF;
            BtnYJ预浸循环.BackColor = OmronPLC.GetSJ酸浸循环.Value ? ColorON : ColorOFF;

            BtnDD导电1段.BackColor = OmronPLC.GetDD导电1段泵.Value ? ColorON : ColorOFF;
            BtnDD导电2段.BackColor = OmronPLC.GetDD导电2段泵.Value ? ColorON : ColorOFF;
            //BtnDD导电3段.BackColor = OmronPLC.GetDD导电3段泵.Value ? ColorON : ColorOFF;
            //BtnDD导电4段.BackColor = OmronPLC.GetDD导电4段泵.Value ? ColorON : ColorOFF;

            BtnSX水洗5.BackColor = OmronPLC.GetSX水洗5.Value ? ColorON : ColorOFF;
            BtnSX水洗6.BackColor = OmronPLC.GetSX水洗6.Value ? ColorON : ColorOFF;
            BtnSX酸洗喷淋.BackColor = OmronPLC.GetSX酸洗喷淋.Value ? ColorON : ColorOFF;
            BtnSX酸洗循环.BackColor = OmronPLC.GetSX酸洗循环.Value ? ColorON : ColorOFF;
            BtnSX水洗7.BackColor = OmronPLC.GetSX水洗7.Value ? ColorON : ColorOFF;
            BtnSX水洗8.BackColor = OmronPLC.GetSX水洗8.Value ? ColorON : ColorOFF;

            BtnKYH抗氧化.BackColor = OmronPLC.GetKYH抗氧化.Value ? ColorON : ColorOFF;
            BtnSX水洗9.BackColor = OmronPLC.GetSX水洗9.Value ? ColorON : ColorOFF;
            BtnSX水洗10.BackColor = OmronPLC.GetSX水洗10.Value ? ColorON : ColorOFF;
            BtnSX水洗11.BackColor = OmronPLC.GetSX水洗11.Value ? ColorON : ColorOFF;
            BtnZL整流机冷却泵.BackColor = OmronPLC.GetZLJ整流机冷却泵.Value ? ColorON : ColorOFF;



            BtnTC铜槽循环泵1.BackColor = OmronPLC.D镀铜槽状态[0].Get喷流泵[0].Value ? ColorON : ColorOFF;

            Btn镀铜1喷流泵1.BackColor = OmronPLC.D镀铜槽状态[1].Get喷流泵[0].Value ? ColorON : ColorOFF;
            Btn镀铜1喷流泵2.BackColor = OmronPLC.D镀铜槽状态[1].Get喷流泵[1].Value ? ColorON : ColorOFF;

            Btn镀铜2喷流泵1.BackColor = OmronPLC.D镀铜槽状态[1].Get喷流泵[0].Value ? ColorON : ColorOFF;
            Btn镀铜2喷流泵2.BackColor = OmronPLC.D镀铜槽状态[1].Get喷流泵[1].Value ? ColorON : ColorOFF;

            Btn镀铜3喷流泵1.BackColor = OmronPLC.D镀铜槽状态[2].Get喷流泵[0].Value ? ColorON : ColorOFF;
            Btn镀铜3喷流泵2.BackColor = OmronPLC.D镀铜槽状态[2].Get喷流泵[1].Value ? ColorON : ColorOFF;

            Btn镀铜4喷流泵1.BackColor = OmronPLC.D镀铜槽状态[3].Get喷流泵[0].Value ? ColorON : ColorOFF;
            Btn镀铜4喷流泵2.BackColor = OmronPLC.D镀铜槽状态[3].Get喷流泵[1].Value ? ColorON : ColorOFF;

            Btn镀铜5喷流泵1.BackColor = OmronPLC.D镀铜槽状态[4].Get喷流泵[0].Value ? ColorON : ColorOFF;
            Btn镀铜5喷流泵2.BackColor = OmronPLC.D镀铜槽状态[4].Get喷流泵[1].Value ? ColorON : ColorOFF;

            Btn镀铜6喷流泵1.BackColor = OmronPLC.D镀铜槽状态[5].Get喷流泵[0].Value ? ColorON : ColorOFF;
            Btn镀铜6喷流泵2.BackColor = OmronPLC.D镀铜槽状态[5].Get喷流泵[1].Value ? ColorON : ColorOFF;

            Btn镀铜7喷流泵1.BackColor = OmronPLC.D镀铜槽状态[6].Get喷流泵[0].Value ? ColorON : ColorOFF;
            Btn镀铜7喷流泵2.BackColor = OmronPLC.D镀铜槽状态[6].Get喷流泵[1].Value ? ColorON : ColorOFF;

            Btn镀铜8喷流泵1.BackColor = OmronPLC.D镀铜槽状态[7].Get喷流泵[0].Value ? ColorON : ColorOFF;
            Btn镀铜8喷流泵2.BackColor = OmronPLC.D镀铜槽状态[7].Get喷流泵[1].Value ? ColorON : ColorOFF;

            #endregion


            #region 温度、电磁阀、补水控制区
            btn除油温控开关.BackColor = OmronPLC.CY除油温度.温控开关状态.Value ? ColorON : ColorOFF;
            btn热水洗温控开关.BackColor = OmronPLC.RS热水洗温度.温控开关状态.Value ? ColorON : ColorOFF;
            btn整流机冷却槽温控开关.BackColor = OmronPLC.ZL整流机冷却温度.温控开关状态.Value ? ColorON : ColorOFF;
     
            btn微蚀温控开关.BackColor = OmronPLC.WS微蚀温度.温控开关状态.Value ? ColorON : ColorOFF;
            btn镀铜温控开关.BackColor = OmronPLC.DT镀铜温度.温控开关状态.Value ? ColorON : ColorOFF;
       
            btnHG烘干温控开关.BackColor = OmronPLC.HG烘干加热温度.温控开关状态.Value ? ColorON : ColorOFF;
            BtnSJ酸浸温控开关.BackColor = OmronPLC.SJ酸浸温度.温控开关状态.Value ? ColorON : ColorOFF;
            btnKYH抗氧化温控开关.BackColor = OmronPLC.KYH抗氧化槽温度.温控开关状态.Value ? ColorON : ColorOFF;
            btnRSC热水槽温度开关.BackColor = OmronPLC.RS热水槽温度.温控开关状态.Value ? ColorON : ColorOFF;

            btnGL隔里水补水电磁阀.BackColor = OmronPLC.GetGL隔离水洗补水阀.Value ? ColorON : ColorOFF;
            btn热水洗补水电磁阀.BackColor = OmronPLC.GetRS热水洗补水阀.Value ? ColorON : ColorOFF;
            btn水洗2补水电磁阀.BackColor = OmronPLC.GetSX水洗2补水阀.Value ? ColorON : ColorOFF;
            btn水洗4补水电磁阀.BackColor = OmronPLC.GetSX水洗4补水阀.Value ? ColorON : ColorOFF;
            btn水洗6补水电磁阀.BackColor = OmronPLC.GetSX水洗6补水阀.Value ? ColorON : ColorOFF;
            btn水洗9补水电磁阀.BackColor = OmronPLC.GetSX水洗9补水阀.Value ? ColorON : ColorOFF;
            btn水洗10补水电磁阀.BackColor = OmronPLC.GetSX水洗10补水阀.Value ? ColorON : ColorOFF;
            btnZLJ整流机槽补水电磁阀.BackColor = OmronPLC.GetZLJ整流机副槽补水阀.Value ? ColorON : ColorOFF;

            Btn_1_导电补水电磁阀.BackColor = OmronPLC.Get_1_导电滚轮副槽补水阀.Value ? ColorON : ColorOFF;
     

            #endregion

            #region 其它开关区
            btnRTC溶铜槽打入循环泵浦开关.BackColor = OmronPLC.GetRTC溶铜槽打入循环泵浦开关.Value ? ColorON : ColorOFF;
            btnCRS搅拌开关.BackColor = OmronPLC.GetCRS搅拌开关.Value ? ColorON : ColorOFF;
            btnCRS铜粉喂料开关.BackColor = OmronPLC.GetTF铜粉喂料开关.Value ? ColorON : ColorOFF;
            btn溶铜槽打出循环泵浦开关.BackColor = OmronPLC.GetRTC溶铜槽打出循环泵浦开关.Value ? ColorON : ColorOFF;

            btnws微蚀搅拌开关.BackColor = OmronPLC.GetWS微蚀搅拌开关.Value ? ColorON : ColorOFF;
            btnws微蚀溶解泵.BackColor = OmronPLC.GetWS微蚀溶解槽泵.Value ? ColorON : ColorOFF;
            Btn上视窗检知开启.BackColor = OmronPLC.GetSS上视窗检知.Value ? ColorON : ColorOFF;
            Btn吸铜粉开关.BackColor = OmronPLC.GetXTF吸铜粉开关.Value ? ColorON : ColorOFF;
            btnQw前微蚀打入后微蚀桶.BackColor = OmronPLC.GetQW前微蚀打入后微蚀桶.Value ? ColorON : ColorOFF;
            #endregion

            #region MES

            #endregion

            #region 产线控制
            btn传送启动.BackColor = OmronPLC.GetZD自动启动.Value? ColorON : ColorOFF;
            btn传送停止.BackColor = OmronPLC.GetZD自动停止.Value ? ColorON : ColorOFF;
            btn周边泵自动启动.BackColor = OmronPLC.GetZB周边泵自动启动.Value ? ColorON : ColorOFF;            
            btn节能模式开.BackColor = OmronPLC.GetJN节能模式.Value ? ColorON : ColorOFF;

            btn静音.BackColor = OmronPLC.SetJY静音.Value ? ColorON : ColorOFF;
            btn异常复位.BackColor = OmronPLC.SetYC异常复归.Value ? ColorON : ColorOFF;

            lbl市水水表1.Text = OmronPLC.SB水表1.ToString("f2");
            lbl纯水水表2.Text = OmronPLC.SB水表2.ToString("f2");
            lbl电表1.Text = (OmronPLC.DB电表).ToString("f0");
            #endregion

            #region 指示灯
            lamp除油加热.LanternBackground = OmronPLC.CY除油温度.加热指示 ? LampColorON : LampColorOFF;
            lamp除油冷却.LanternBackground = OmronPLC.CY除油温度.冷却指示 ? LampColorON : LampColorOFF;

            lamp热水洗加热.LanternBackground = OmronPLC.RS热水洗温度.加热指示 ? LampColorON : LampColorOFF;
            lampRS热水槽加热.LanternBackground = OmronPLC.RS热水槽温度.加热指示 ? LampColorON : LampColorOFF;

            lamp微蚀加热.LanternBackground = OmronPLC.WS微蚀温度.加热指示 ? LampColorON : LampColorOFF;
            lamp微蚀冷却.LanternBackground = OmronPLC.WS微蚀温度.冷却指示 ? LampColorON : LampColorOFF;

            lampKYH抗氧化加热.LanternBackground = OmronPLC.KYH抗氧化槽温度.加热指示 ? LampColorON : LampColorOFF;
            lampKYH抗氧化冷却.LanternBackground = OmronPLC.KYH抗氧化槽温度.冷却指示 ? LampColorON : LampColorOFF;

            lamp铜槽加热.LanternBackground = OmronPLC.DT镀铜温度.加热指示 ? LampColorON : LampColorOFF;
            lamp铜槽冷却.LanternBackground = OmronPLC.DT镀铜温度.冷却指示 ? LampColorON : LampColorOFF;

            lampSX酸洗加热.LanternBackground = OmronPLC.SJ酸浸温度.加热指示 ? LampColorON : LampColorOFF;
            lampSX酸洗冷却.LanternBackground = OmronPLC.SJ酸浸温度.冷却指示 ? LampColorON : LampColorOFF;

            lamp整流机冷却.LanternBackground = OmronPLC.ZL整流机冷却温度.冷却指示 ? LampColorON : LampColorOFF;
            lampHG烘干加热.LanternBackground = OmronPLC.HG烘干加热温度.加热指示 ? LampColorON : LampColorOFF;
            
            Lamp卷入上转轴指示.LanternBackground = OmronPLC.RL入料上下轴指示.Value ? LampColorON : LampColorOFF;
            Lamp卷入下转轴指示.LanternBackground = OmronPLC.RL入料上下轴指示.Value ?  LampColorOFF : LampColorON ;

            Lamp卷出上转轴指示.LanternBackground = OmronPLC.CL出料上下轴指示.Value ? LampColorON : LampColorOFF;
            Lamp卷出下转轴指示.LanternBackground = OmronPLC.CL出料上下轴指示.Value ? LampColorOFF : LampColorON;
            #endregion

        }//end定时器刷新


        //上料设定区
        private void FillRecipe(RecipeView view)
        {
            txt料号.Text = view.Name;

            txt宽度.Text = view.Width.ToString();
            //txt高度.Text = view.Height.ToString();
            //txt面积.Text = view.AreaDm2.ToString("f2");
       //     txt浮板位置.Text = view.F浮板位置.ToString();

            txtC面电流密度.Text = view.C面电流密度ASD.ToString();
            txtS面电流密度.Text = view.S面电流密度ASD.ToString();

            txtC面厚度.Text = view.D镀铜C面厚度.ToString("f2");
            txtS面厚度.Text = view.D镀铜S面厚度.ToString("f2");
            txt板厚.Text = view.Thickness.ToString("f2");
            

            txt镀铜时间.Text = view.D镀铜时间.ToString();
            txt镀铜速度米每分.Text = view.D镀铜速度mpmin.ToString("f2");
            txt料号线速.Text = view.D镀铜速度.ToString("f2");

            //txt卡板警报电压.Text = view.K卡板报警电压.ToString("f2");
            //txt除油1频率.Text = view.C除油1频率.ToString();
            //txt除油2频率.Text = view.C除油2频率.ToString();


            //镀铜段                   
            {
                var type = this.GetType();
                var Flags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
                for (int i = 1; i <= KorbeRTR.Config.镀铜段数; i++)
                {
                    int slot = i - 1;

                    var tb = type.GetField("tbxCurrentCoefficient" + i.ToString(), Flags).GetValue(this) as TextBox;
                    tb.Text = view.CuSlots[slot].D电流系数.ToString();

                    tb = type.GetField("tbxCCurrent" + i.ToString(), Flags).GetValue(this) as TextBox;
                    tb.Text = view.CuSlots[slot].C面电流.ToString("f1");

                    tb = type.GetField("tbxSCurrent" + i.ToString(), Flags).GetValue(this) as TextBox;
                    tb.Text = view.CuSlots[slot].S面电流.ToString("f1");

                    tb = type.GetField("tbxFlow" + i.ToString(), Flags).GetValue(this) as TextBox;
                    tb.Text = view.CuSlots[slot].Flow.ToString();
                }
            }

            //槽选择
            //{
            //    var list = new CheckBox[] {
            //            ckbx除油1使用, ckbx热水洗2使用, ckbx水洗3使用, ckbx水洗4使用,
            //            ckbx微蚀5使用, ckbx水洗6使用, ckbx水洗7使用, ckbx预浸8使用
            //        };

            //    string en = view.C槽选择;
            //    for (int i = 0; i < list.Length; i++)
            //    {
            //        list[i].Checked = (i < en.Length) ? (en[i] != '0') : false;
            //    }
            //}
        }
    

        private void ClearRecipe()
        {
            txt批号.Text = "";

            FillRecipe(new RecipeView());
        }

        
        
        /// <summary>
        /// 
        /// </summary>
        private void btn设定默认料号_Click(object sender, EventArgs e)
        {
            var gl = Global.GetInstance();
            if (!gl.CurrentUser.Check生产料号操作权限())
            {
                MessageBox.Show("您没有生产料号操作权限, 请联系管理员!", "提示");
                return;
            }

            //先删除料号
            if (OmronPLC.SL上料参数.L料号ID.Value != 0)
            {
                MessageBox.Show("料号ID不为0，请先删除原来设定料号。", "提示");
                return;
            }

            //设定默认料号
            var recipe = gl.CurrentRecipeView;
            if (recipe == null)
            {
                MessageBox.Show("未选择料号!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var id = (UInt16)recipe.Id;
            var LR = RecipeView.SelectById(id);
            if (LR == null || LR.Id != recipe.Id)
            {
                MessageBox.Show("料号ID错误!" + id.ToString());
                return;
            }

            if (!recipe.RecipeViewVerify())
                return;

            if (string.IsNullOrWhiteSpace(txt批号.Text))
            {
                MessageBox.Show("批号不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //if (OmronPLC.YX == 0)
            //{   // 不允许切换料号
            //    return;
            //}

            //加判断能否设定料号参数
            if (OmronPLC.Flag允许切换线速.Value)
            {   // 不同料号灯绿色, 可以切换任何料号
                // Pass
            }
            else
            {   // 不同料号灯黄色
                if (OmronPLC.Flag允许切换料号.Value)
                {   // 相同绿色
                    //  if (Math.Abs(recipe.D镀铜速度 - OmronPLC.SL上料参数.D镀铜速度.Value) > 0.5)
                    if (Math.Abs(recipe.D镀铜速度 - OmronPLC.SJ实际线速.Value) > 0.05)
                    {
                        string mes = "recipe.D镀铜速度 = " + recipe.D镀铜速度.ToString() + "SL上料参数.D镀铜速度= " + OmronPLC.SL上料参数.D镀铜速度.Value.ToString()
                            + " SJ实际线速=" + OmronPLC.SJ实际线速.Value.ToString();
                        MessageBox.Show("当前只能切换电镀速度相同的料号!不同速度料号请等待." + mes, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                else
                {   // 相同黄色
                    MessageBox.Show("不能切换线速!请等待", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            OmronPLC.SL上料参数.K宽度.Value = recipe.Width;
            OmronPLC.SL上料参数.D镀铜速度.Value = recipe.D镀铜速度;

     //       OmronPLC.SL上料参数.K卡板电压.Value = recipe.K卡板报警电压;

            for (int i = 0; i < Config.镀铜段数; i++)
            {
                OmronPLC.SL上料参数.T铜槽[i].C面电流.Value = recipe.CuSlots[i].C面电流;
                OmronPLC.SL上料参数.T铜槽[i].S面电流.Value = recipe.CuSlots[i].S面电流;
                OmronPLC.SL上料参数.T铜槽[i].喷流频率.Value = recipe.CuSlots[i].Flow;
                //OmronPLC.SL上料参数.T铜槽[i].下喷流频率.Value = 0;
            }

            OmronPLC.SL上料参数.L料号ID.Value = id;

            var loading = new LoadingView()
            {
                Loader = gl.CurrentUser.UserName,
                Time = DateTime.Now,
                Batch = txt批号.Text,
                LoadingRecipeId = LR.Id,
                LoadingRecipe = LR
            };

            if (LoadingView.Add(loading))
            {
                MessageBox.Show("设定料号成功.", "提示");
                //txt料号.BackColor = Color.Lime;
            }
            else
            {
                MessageBox.Show("设定料号失败!", "提示");
            }

            {
                var op = new OperationRecord
                {
                    Time = DateTime.Now,
                    User = gl.CurrentUser != null ? gl.CurrentUser.UserName : "System",
                    OperationType = "料号设置/删除",
                    Operation = "设置料号:"
                                + gl.CurrentRecipeView.Id.ToString()
                                + ","
                                + gl.CurrentRecipeView.Name
                };

                OperationRecord.Add(op);
            }
        }

        private void btn删除设定料号_Click(object sender, EventArgs e)
        {
            var gl = Global.GetInstance();
            if (!gl.CurrentUser.Check生产料号操作权限())
            {
                MessageBox.Show("您没有生产料号操作权限, 请联系管理员!", "提示");
                return;
            }

            DialogResult result = MessageBox.Show("您是否要删除设定料号？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result != DialogResult.Yes)
            {
                return;
            }

            {
                var op = new OperationRecord
                {
                    Time = DateTime.Now,
                    User = gl.CurrentUser != null ? gl.CurrentUser.UserName : "System",
                    OperationType = "料号设置/删除",
                    Operation = "删除料号:"
                                + gl.CurrentRecipeView.Id.ToString()
                                + ","
                                + gl.CurrentRecipeView.Name
                };

                OperationRecord.Add(op);
            }

            gl.CurrentRecipeView = null;

            ClearRecipe();

            OmronPLC.SL上料参数.L料号ID.Value = 0;
            OmronPLC.SL上料参数.K宽度.Value = 0;
            OmronPLC.SL上料参数.D镀铜速度.Value = 0;
            OmronPLC.SL上料参数.K卡板电压.Value = 0;


            for (int i = 0; i < Config.镀铜段数; i++)
            {
                OmronPLC.SL上料参数.T铜槽[i].C面电流.Value = 0;
                OmronPLC.SL上料参数.T铜槽[i].S面电流.Value = 0;
                OmronPLC.SL上料参数.T铜槽[i].喷流频率.Value = 0;
                //OmronPLC.SL上料参数.T铜槽[i].下喷流频率.Value = 0;
            }
         
            MessageBox.Show("删除设定料号成功", "提示！");
        }

        #region 泵浦控制区
        private void BtnGL隔离水洗_Click(object sender, EventArgs e)
        {
            OmronPLC.SetGL隔离水洗.Value = true;
        }

        private void BtnCY除油喷淋_Click(object sender, EventArgs e)
        {
            OmronPLC.SetCY除油喷淋.Value = true;
        }

        private void BtnCY除油循环_Click(object sender, EventArgs e)
        {
            OmronPLC.SetCY除油循环.Value = true;
        }

        private void Btn热水洗喷淋_Click(object sender, EventArgs e)
        {
            OmronPLC.SetRS热水洗喷淋.Value = true;
        }

        private void BtnRS热水洗循环_Click(object sender, EventArgs e)
        {
            OmronPLC.SetRS热水洗循环.Value = true;
        }

        private void Btn水洗1_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗1.Value = true;
        }

        private void BtnSJR水加热循环泵_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSJR水加热循环泵.Value = true;
        }

        private void BtnDQ打气开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SetDQ打气开关.Value = true;
        }

        private void Btn水洗2_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗2.Value = true;
        }

        private void BtnWSPL微蚀喷淋_Click(object sender, EventArgs e)
        {
            OmronPLC.SetWS微蚀喷淋.Value = true;
        }

        private void BtnWSXH微蚀循环_Click(object sender, EventArgs e)
        {
            OmronPLC.SetWS微蚀循环.Value = true;
        }

        private void BtnSX水洗3_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗3.Value = true;
        }

        private void BtnSX水洗4_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗4.Value = true;
        }

        private void BtnYJ预浸喷淋_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSJ酸浸喷淋.Value = true;
        }

        private void BtnYJ预浸循环_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSJ酸浸循环.Value = true;
        }

        private void BtnDD导电1段_Click(object sender, EventArgs e)
        {
            OmronPLC.SetDD导电1段泵.Value = true;
        }

        private void BtnDD导电2段_Click(object sender, EventArgs e)
        {
            OmronPLC.SetDD导电2段泵.Value = true;
        }

        private void BtnDD导电3段_Click(object sender, EventArgs e)
        {
            OmronPLC.SetDD导电3段泵.Value = true;
        }

        private void BtnDD导电4段_Click(object sender, EventArgs e)
        {
            OmronPLC.SetDD导电4段泵.Value = true;
        }

        private void BtnSX水洗5_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗5.Value = true;
        }

        private void BtnSX酸洗喷淋_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX酸洗喷淋.Value = true;
        }

        private void BtnSX酸洗循环_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX酸洗循环.Value = true;
        }

        private void BtnKYH抗氧化_Click(object sender, EventArgs e)
        {
            OmronPLC.SetKYH抗氧化.Value = true;
        }

        private void BtnSX水洗9_Click_2(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗9.Value = true;
        }

        private void BtnSX水洗10_Click_1(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗10.Value = true;
        }

        private void BtnSX水洗11_Click_1(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗11.Value = true;
        }

        private void btn整流机冷却泵_Click(object sender, EventArgs e)
        {
            OmronPLC.SetZLJ整流机冷却泵.Value = true;
        }

        private void Btn镀铜1喷流泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[0].Set喷流泵[0].Value = true;
        }

        private void Btn镀铜1喷流泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[0].Set喷流泵[1].Value = true;
        }

        private void Btn镀铜2喷流泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[1].Set喷流泵[0].Value = true;
        }

        private void Btn镀铜2喷流泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[1].Set喷流泵[1].Value = true;
        }

        private void Btn镀铜3喷流泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[2].Set喷流泵[0].Value = true;
        }

        private void Btn镀铜3喷流泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[2].Set喷流泵[1].Value = true;
        }

        private void Btn镀铜4喷流泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[3].Set喷流泵[0].Value = true;
        }

        private void Btn镀铜4喷流泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[3].Set喷流泵[1].Value = true;
        }

        private void Btn镀铜5喷流泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[4].Set喷流泵[0].Value = true;
        }

        private void Btn镀铜5喷流泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[4].Set喷流泵[1].Value = true;
        }

        private void Btn镀铜6喷流泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[5].Set喷流泵[0].Value = true;
        }

        private void Btn镀铜6喷流泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[5].Set喷流泵[1].Value = true;
        }

        private void Btn镀铜7喷流泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[6].Set喷流泵[0].Value = true;
        }

        private void Btn镀铜7喷流泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[6].Set喷流泵[1].Value = true;
        }

        private void Btn镀铜8喷流泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[7].Set喷流泵[0].Value = true;
        }

        private void Btn镀铜8喷流泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.D镀铜槽状态[7].Set喷流泵[1].Value = true;
        }

        private void BtnTC铜槽循环泵1_Click(object sender, EventArgs e)
        {
            OmronPLC.SetTC铜槽循环泵1.Value = true;
        }

        private void BtnTC铜槽循环泵2_Click(object sender, EventArgs e)
        {
            OmronPLC.SetTC铜槽循环泵2.Value = true;
        }

        private void BtnZL整流机冷却泵_Click(object sender, EventArgs e)
        {
            OmronPLC.SetZLJ整流机冷却泵.Value = true;
        }

        private void BtnLF冷风吹干风机1_Click(object sender, EventArgs e)
        {
            OmronPLC.SetLF冷风吹干风机1.Value = true;
        }

        private void BtnLF冷风吹干风机2_Click(object sender, EventArgs e)
        {
            OmronPLC.SetLF冷风吹干风机2.Value = true;
        }

        private void BtnRF热风吹干风机1_Click(object sender, EventArgs e)
        {
            OmronPLC.SetRF热风吹干风机1.Value = true;
        }

        private void BtnRF热风吹干风机2_Click(object sender, EventArgs e)
        {
            OmronPLC.SetRF热风吹干风机2.Value = true;
        }        
        #endregion

        #region 温度、电磁阀、补水控制区
        private void btn除油温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.CY除油温度.温控开关.Value = !OmronPLC.CY除油温度.温控开关.Value; ;
        }

        private void btn热水洗温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.RS热水洗温度.温控开关.Value = !OmronPLC.RS热水洗温度.温控开关.Value; ;
        }

        private void btn整流机冷却槽温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.ZL整流机冷却温度.温控开关.Value = !OmronPLC.ZL整流机冷却温度.温控开关.Value;
        }

        private void BtnSX酸洗槽温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SX酸洗槽温度.温控开关.Value = !OmronPLC.SX酸洗槽温度.温控开关.Value;
        }

        private void btn镀铜温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.DT镀铜温度.温控开关.Value = !OmronPLC.DT镀铜温度.温控开关.Value;
        }

        private void btn微蚀温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.WS微蚀温度.温控开关.Value = !OmronPLC.WS微蚀温度.温控开关.Value;
        }

        private void BtnTC铜槽添加温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.DT镀铜温度.温控开关.Value = !OmronPLC.DT镀铜温度.温控开关.Value;
        }

        private void BtnSJ酸浸温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SJ酸浸温度.温控开关.Value = !OmronPLC.SJ酸浸温度.温控开关.Value;
        }

        private void btnHG烘干温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.HG烘干加热温度.温控开关.Value = !OmronPLC.HG烘干加热温度.温控开关.Value;
        }


        private void btnKYH抗氧化温控开关_Click(object sender, EventArgs e)
        {
            OmronPLC.KYH抗氧化槽温度.温控开关.Value = !OmronPLC.KYH抗氧化槽温度.温控开关.Value;
        }

        private void btnRSC热水槽温度开关_Click(object sender, EventArgs e)
        {
            OmronPLC.RS热水槽温度.温控开关.Value = !OmronPLC.RS热水槽温度.温控开关.Value;
        }

        private void btnGL隔里水补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.SetGL隔离水洗补水阀.Value = !OmronPLC.SetGL隔离水洗补水阀.Value;
        }

        private void btnZLJ整流机槽补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.SetZLJ整流机副槽补水阀.Value = !OmronPLC.SetZLJ整流机副槽补水阀.Value;
        }

        private void btn热水洗补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.SetRS热水洗补水阀.Value = !OmronPLC.SetRS热水洗补水阀.Value;
        }

        private void btn水洗2补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗2补水阀.Value = !OmronPLC.SetSX水洗2补水阀.Value;
        }

        private void btn水洗4补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗4补水阀.Value = !OmronPLC.SetSX水洗4补水阀.Value;
        }

        private void btn水洗6补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗6补水阀.Value = !OmronPLC.SetSX水洗6补水阀.Value;
        }

        private void btn水洗9补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗9补水阀.Value = !OmronPLC.SetSX水洗9补水阀.Value;
        }

        private void btn水洗10补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗10补水阀.Value = !OmronPLC.SetSX水洗10补水阀.Value;
        }

        private void Btn_1_导电补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.Set_1_导电滚轮副槽补水阀.Value = !OmronPLC.Set_1_导电滚轮副槽补水阀.Value;
        }

        private void Btn_2_导电补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.Set_2_导电滚轮副槽补水阀.Value = !OmronPLC.Set_2_导电滚轮副槽补水阀.Value;
        }

        private void Btn_3_导电补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.Set_3_导电滚轮副槽补水阀.Value = !OmronPLC.Set_3_导电滚轮副槽补水阀.Value;
        }

        private void Btn_4_导电补水电磁阀_Click(object sender, EventArgs e)
        {
            OmronPLC.Set_4_导电滚轮副槽补水阀.Value = !OmronPLC.Set_4_导电滚轮副槽补水阀.Value;
        }

        #endregion

        #region 其它开关区
        private void btnRTC溶铜槽打入循环泵浦开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SetRTC溶铜槽打入循环泵浦开关.Value = true;
        }

        private void btnCRS搅拌开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SetCRS搅拌开关.Value = true;
        }

        private void btnCRS铜粉喂料开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SetTF铜粉喂料开关.Value = true;
        }

        private void btn溶铜槽打出循环泵浦开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SetRTC溶铜槽打出循环泵浦开关.Value = true;
        }

        private void btnws微蚀搅拌开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SetWS微蚀搅拌开关.Value = true;
        }

        private void btnws微蚀溶解泵_Click(object sender, EventArgs e)
        {
            OmronPLC.SetWS微蚀溶解槽泵.Value = true;
        }

        private void btnQw前微蚀打入后微蚀桶_Click(object sender, EventArgs e)
        {
            OmronPLC.SetQW前微蚀打入后微蚀桶.Value = true;
        }

        private void Btn上视窗检知开启_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSS上视窗检知.Value = true;
        }

        #endregion

        #region  右下功能区
        private void btn传送启动_Click(object sender, EventArgs e)
        {
            OmronPLC.SetZD自动启动.Value = true;
        }

        private void btn传送停止_Click(object sender, EventArgs e)
        {
            OmronPLC.SetZD自动停止.Value = true;
        }

        private void btn静音_Click(object sender, EventArgs e)
        {
            OmronPLC.SetJY静音.Value = !OmronPLC.SetJY静音.Value;
        }

        private void btn异常复位_Click(object sender, EventArgs e)
        {
            OmronPLC.SetYC异常复归.Value = !OmronPLC.SetYC异常复归.Value;
        }

        private void btn周边泵自动启动_Click(object sender, EventArgs e)
        {
            if (!OmronPLC.GetZB周边泵自动启动.Value)
            {   // 打开
                OmronPLC.SetZB周边泵自动启动.Value = true;
                return;
            }

            if (!ProductionLine有料())
            {   // 产线无料
                OmronPLC.SetZB周边泵自动启动.Value = true;
                return;
            }

            MessageBox.Show("产线有料,禁止关闭泵浦!", "禁止关闭泵浦", MessageBoxButtons.OK);
        }

        private void btn节能模式开_Click(object sender, EventArgs e)
        {
            OmronPLC.SetJN节能模式.Value = true;
        }
     

        private void btn市水阀_Click(object sender, EventArgs e)
        {
//           OmronPLC.SetSSF市水阀.Value = true;
        }
        #endregion

        private void txt料号_KeyUp(object sender, KeyEventArgs e)
        {
            //if (e.KeyCode != Keys.Enter)
            //{
            //    return;
            //}

            //string LH = txt料号.Text;
            //if (string.IsNullOrWhiteSpace(LH))
            //{
            //    MessageBox.Show("请输入料号!", "错误", MessageBoxButtons.OK);
            //    return;
            //}

            //try
            //{
            //    var recipe = RecipeView.SelectByNameLike(LH);
            //    if (recipe != null)
            //    {
            //        Global.GetInstance().CurrentRecipeView = recipe;
            //        FillRecipe(recipe);
            //    }
            //}
            //catch(Exception err)
            //{
            //    MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            //}

            e.Handled = true;
        }

        private void btn料号_Click(object sender, EventArgs e)
        {
            tsmBaseData_Click(sender, e);
        }

        private void tsslblNumber_Click(object sender, EventArgs e)
        {

            DialogResult result = MessageBox.Show("是否确定将上料片数和下料片数清零？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                OmronPLC.SL上料片数.Value = 0;
                OmronPLC.XL下料片数.Value = 0;
            }
        }

        private void TSMI_Watch_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormWatch).Name);
                if (!bl)
                {
                    var form = new FormWatch();
                    form.Show();
                }
            }
            catch
            {
            }
        }

        public static bool ProductionLine有料()
        {
            var plc = OmronPLC;

            //if (plc.LH料号.除油有料.Value) return true;

            //if (plc.LH料号.热水洗2有料.Value) return true;

            //if (plc.LH料号.水洗3有料.Value) return true;

            //if (plc.LH料号.水洗4有料.Value) return true;

            //if (plc.LH料号.微蚀5有料.Value) return true;

            //if (plc.LH料号.水洗6有料.Value) return true;

            //if (plc.LH料号.水洗7有料.Value) return true;

            //if (plc.LH料号.酸浸8有料.Value) return true;

            //for(int i=0; i<Config.镀铜槽数; i++)
            //{
            //    if (plc.LH料号.镀铜槽有料A[i].Value) return true;

            //    if (plc.LH料号.镀铜槽有料B[i].Value) return true;
            //}

            //if (plc.LH料号.水洗9有料.Value) return true;

            //if (plc.LH料号.水洗10有料.Value) return true;

            //if (plc.LH料号.水洗11有料.Value) return true;

            return false;
        }

        private void TSMI_TestMES_Click(object sender, EventArgs e)
        {
            try
            {
                bool bl = CheckForm(typeof(FormTestMES).Name);
                if (!bl)
                {
                    var form = new FormTestMES();
                    form.Show();
                }
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
        }

        private void BtnSX水洗6_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗6.Value = !OmronPLC.SetSX水洗6.Value;
        }

        private void BtnSX水洗7_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗7.Value = !OmronPLC.SetSX水洗7.Value;
        }

        private void BtnSX水洗8_Click_1(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗8.Value = !OmronPLC.SetSX水洗8.Value;
        }

        private void BtnSX水洗9_Click_1(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗9.Value = !OmronPLC.SetSX水洗9.Value;
        }

        private void BtnSX水洗10_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗10.Value = !OmronPLC.SetSX水洗10.Value;
        }

        private void BtnSX水洗11_Click(object sender, EventArgs e)
        {
            OmronPLC.SetSX水洗11.Value = !OmronPLC.SetSX水洗11.Value;
        }

        private void Btn卷入工位设定_Click(object sender, EventArgs e)
        {
            if(Combo卷入工位.Text == "上工位")
            {
                OmronPLC.RL入料上下轴选择.Value = true;
                MessageBox.Show("选择上工位");
            }
            else
            {
                OmronPLC.RL入料上下轴选择.Value = false;
            }

            if (Combo卷出工位.Text == "上工位")
            {
                OmronPLC.CL出料上下轴选择.Value = true;
                
            }
            else
            {
                OmronPLC.CL出料上下轴选择.Value = false;
                MessageBox.Show("选择下工位");
            }
            //OmronPLC.RL入料上下轴选择.Value = Combo卷入工位.SelectedIndex == 0 ? true : false;
            //OmronPLC.CL出料上下轴选择.Value = Combo卷出工位.SelectedIndex == 0 ? true : false;
        }

        private void Btn料卷参数设定_Click(object sender, EventArgs e)
        {
            OmronPLC.LJ料卷长度设定.Value = TextLJ料卷长度.Text.Trim().ToDouble();
            OmronPLC.SY剩余报警长度设定.Value = TextSY剩余长度报警.Text.Trim().ToDouble();
        }

        private void tbc多界面数据_DrawItem(object sender, DrawItemEventArgs e)
        {
            Rectangle rec = tbc多界面数据.ClientRectangle;
            e.Graphics.DrawImage(Image.FromFile(BackImage), 0, 0, rec.Width, rec.Height);

            ////设置笔刷
            SolidBrush red = new SolidBrush(Color.FromArgb(131, 223, 56));              // 红色
            SolidBrush yellow = new SolidBrush(Color.FromArgb(185, 89, 136));        //黄色
            SolidBrush blue = new SolidBrush(Color.FromArgb(185, 109, 236));             //蓝色
            SolidBrush four = new SolidBrush(Color.FromArgb(185, 109, 36));             //蓝色
            SolidBrush black = new SolidBrush(Color.Black);            //黑色          
            //                                                           //设置背景
            //                                                           //绘制红色背景
            Rectangle rectangleRed = tbc多界面数据.GetTabRect(0);
            e.Graphics.FillRectangle(red, rectangleRed);
            //绘制黄色背景
            Rectangle rectangleYellow = tbc多界面数据.GetTabRect(1);
            e.Graphics.FillRectangle(yellow, rectangleYellow);
            //绘制黄色背景
            Rectangle rectangleBlue = tbc多界面数据.GetTabRect(2);
            e.Graphics.FillRectangle(blue, rectangleBlue);
            Rectangle rectanglefour = tbc多界面数据.GetTabRect(3);
            e.Graphics.FillRectangle(four, rectanglefour);
            //设置标签文字居中对齐
            StringFormat stringFormat = new StringFormat();
            //设置标签文字
            for (int i = 0; i < tbc多界面数据.TabPages.Count; i++)
            {
                Rectangle re = tbc多界面数据.GetTabRect(i);
                //设置文字字体和文字大小
                e.Graphics.DrawString(tbc多界面数据.TabPages[i].Text, new Font("宋体", 10), black, re, stringFormat);
            }
        }


        private void pBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            double x = e.Location.X;
            double y = e.Location.Y; 

            x = x / pBox1.Width;
            y = y / pBox1.Height;

            int px = (int)(x * 7400);
            int py = (int)(y * 826);

            var img = new Bitmap(pBox1.Image);

            if (px < 400)
            {
                px = 400;
            } 
            if (px > 7000)
            {
                px = 7000;
            }

            img = img.Clone(new Rectangle(px - 400, 0, 800, img.Height), img.PixelFormat);


            var window = new System.Windows.Forms.Form();
            window.Name = "放大图片";
            window.Size = new Size(1000, 850);

            window.BackgroundImageLayout = ImageLayout.Zoom;
            window.BackgroundImage = img;

            window.ShowDialog();
        }

        private void TSMI_BackupDatabase_Click(object sender, EventArgs e)
        {
            try
            {
                Task.Run(
                    () => {
                        try
                        {
                            AuxLib.BackupDatabase(DateTime.Now);
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
                        }
                    }
                );
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + Environment.NewLine + err.StackTrace);
            }
        }

        private void Btn吸铜粉开关_Click(object sender, EventArgs e)
        {
            OmronPLC.SetXTF吸铜粉开关.Value = true;
        }

        private void Btn吸铜粉参数写入_Click(object sender, EventArgs e)
        {
            OmronPLC.TF铜粉吸时间.Value = TB_铜粉吸时间.Text.ToDouble();
            OmronPLC.TF铜粉停吸时间.Value = TB_铜粉停吸时间.Text.ToDouble();
        }

        private void Btn吸铜粉参数刷新_Click(object sender, EventArgs e)
        {
            TB_铜粉吸时间.Text = OmronPLC.TF铜粉吸时间.Value.ToString("F1");
            TB_铜粉停吸时间.Text = OmronPLC.TF铜粉停吸时间.Value.ToString("F1");
        }

     

     
    }

    public static partial class KorbeVCPExtersions
    {
        public static string ToMesString(this LoadingView view)
        {
            var p = view ?? new LoadingView();

            string text = "";
            return text;
        }
    }


}



